@waterx/sdk 2.1.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -169
- package/dist/src/client.d.ts +40 -2
- package/dist/src/client.js +55 -6
- package/dist/src/config.d.ts +66 -3
- package/dist/src/config.js +10 -4
- package/dist/src/constants.d.ts +6 -0
- package/dist/src/constants.js +6 -0
- package/dist/src/core/waterx-account.d.ts +31 -0
- package/dist/src/core/waterx-account.js +26 -0
- package/dist/src/fetch.d.ts +110 -0
- package/dist/src/fetch.js +149 -4
- package/dist/src/generated/bucket_v2_framework/account.d.ts +5 -5
- package/dist/src/generated/bucket_v2_framework/double.d.ts +77 -77
- package/dist/src/generated/bucket_v2_framework/float.d.ts +73 -73
- package/dist/src/generated/bucket_v2_framework/liability.d.ts +33 -33
- package/dist/src/generated/bucket_v2_framework/linked_table.d.ts +5 -5
- package/dist/src/generated/bucket_v2_framework/linked_table.js +2 -2
- package/dist/src/generated/bucket_v2_framework/sheet.d.ts +57 -57
- package/dist/src/generated/bucket_v2_framework/sheet.js +5 -11
- package/dist/src/generated/native_custody/custody_vault.d.ts +46 -32
- package/dist/src/generated/native_custody/custody_vault.js +19 -10
- package/dist/src/generated/native_custody/deps/bucket_v2_framework/sheet.js +1 -3
- package/dist/src/generated/native_custody/events.js +1 -2
- package/dist/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.d.ts +7 -7
- package/dist/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.js +1 -2
- package/dist/src/generated/utils/index.d.ts +7 -7
- package/dist/src/generated/utils/index.js +9 -6
- package/dist/src/generated/waterx_account/account.d.ts +124 -71
- package/dist/src/generated/waterx_account/account.js +64 -29
- package/dist/src/generated/waterx_account/deps/bucket_v2_framework/sheet.js +1 -3
- package/dist/src/generated/waterx_account/direct_rule.d.ts +5 -5
- package/dist/src/generated/waterx_account/events.d.ts +10 -0
- package/dist/src/generated/waterx_account/events.js +31 -50
- package/dist/src/generated/waterx_constant_rule/constant_rule.d.ts +68 -0
- package/dist/src/generated/waterx_constant_rule/constant_rule.js +59 -0
- package/dist/src/generated/waterx_constant_rule/deps/bucket_v2_framework/float.d.ts +8 -0
- package/dist/src/generated/waterx_constant_rule/deps/bucket_v2_framework/float.js +10 -0
- package/dist/src/generated/waterx_constant_rule/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/waterx_constant_rule/deps/sui/vec_map.js +27 -0
- package/dist/src/generated/waterx_credit/credit_registry.d.ts +9 -9
- package/dist/src/generated/waterx_credit/credit_registry.js +1 -2
- package/dist/src/generated/waterx_credit/limited_supply.d.ts +17 -17
- package/dist/src/generated/waterx_oracle/aggregator.js +1 -2
- package/dist/src/generated/waterx_oracle/collector.d.ts +17 -17
- package/dist/src/generated/waterx_oracle/collector.js +1 -1
- package/dist/src/generated/waterx_oracle/oracle.d.ts +5 -5
- package/dist/src/generated/waterx_perp/account_data.d.ts +5 -5
- package/dist/src/generated/waterx_perp/account_data.js +1 -2
- package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/sheet.js +1 -3
- package/dist/src/generated/waterx_perp/events.d.ts +181 -181
- package/dist/src/generated/waterx_perp/events.js +87 -173
- package/dist/src/generated/waterx_perp/global_config.d.ts +3 -3
- package/dist/src/generated/waterx_perp/global_config.js +6 -12
- package/dist/src/generated/waterx_perp/keyed_big_vector.d.ts +9 -9
- package/dist/src/generated/waterx_perp/keyed_big_vector.js +1 -2
- package/dist/src/generated/waterx_perp/lp_pool.d.ts +115 -115
- package/dist/src/generated/waterx_perp/lp_pool.js +11 -22
- package/dist/src/generated/waterx_perp/market_config.d.ts +61 -43
- package/dist/src/generated/waterx_perp/market_config.js +29 -22
- package/dist/src/generated/waterx_perp/math.d.ts +7 -7
- package/dist/src/generated/waterx_perp/order_book.d.ts +47 -47
- package/dist/src/generated/waterx_perp/position.d.ts +99 -99
- package/dist/src/generated/waterx_perp/position.js +6 -12
- package/dist/src/generated/waterx_perp/request.d.ts +67 -67
- package/dist/src/generated/waterx_perp/request.js +2 -3
- package/dist/src/generated/waterx_perp/response.d.ts +35 -35
- package/dist/src/generated/waterx_perp/response.js +1 -2
- package/dist/src/generated/waterx_perp/trading.d.ts +303 -179
- package/dist/src/generated/waterx_perp/trading.js +99 -14
- package/dist/src/generated/waterx_perp_view/view.js +5 -10
- package/dist/src/generated/waterx_pyth_rule/pyth_rule.d.ts +5 -5
- package/dist/src/generated/waterx_pyth_rule/pyth_rule.js +1 -2
- package/dist/src/generated/waterx_referral/referral_table.d.ts +5 -5
- package/dist/src/generated/waterx_referral/referral_table.js +1 -2
- package/dist/src/generated/waterx_staking/waterx_staking.d.ts +19 -19
- package/dist/src/generated/waterx_staking/waterx_staking.js +10 -20
- package/dist/src/generated/waterx_supra_rule/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/waterx_supra_rule/deps/sui/vec_map.js +27 -0
- package/dist/src/generated/waterx_supra_rule/supra_rule.d.ts +158 -0
- package/dist/src/generated/waterx_supra_rule/supra_rule.js +148 -0
- package/dist/src/generated/withdrawal_queue/deps/bucket_v2_framework/float.d.ts +8 -0
- package/dist/src/generated/withdrawal_queue/deps/bucket_v2_framework/float.js +10 -0
- package/dist/src/generated/withdrawal_queue/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/withdrawal_queue/deps/sui/vec_map.js +27 -0
- package/dist/src/generated/withdrawal_queue/withdrawal_queue.d.ts +444 -4
- package/dist/src/generated/withdrawal_queue/withdrawal_queue.js +417 -4
- package/dist/src/generated/wormhole_bridge/wormhole_bridge.d.ts +214 -74
- package/dist/src/generated/wormhole_bridge/wormhole_bridge.js +158 -29
- package/dist/src/index.d.ts +4 -3
- package/dist/src/index.js +3 -2
- package/dist/src/prediction/account.d.ts +96 -0
- package/dist/src/prediction/account.js +230 -0
- package/dist/src/prediction/admin.d.ts +47 -0
- package/dist/src/prediction/admin.js +105 -0
- package/dist/src/prediction/bcs.d.ts +22 -0
- package/dist/src/prediction/bcs.js +240 -0
- package/dist/src/prediction/client.d.ts +75 -0
- package/dist/src/prediction/client.js +164 -0
- package/dist/src/prediction/config.d.ts +60 -0
- package/dist/src/prediction/config.js +75 -0
- package/dist/src/prediction/constants.d.ts +44 -0
- package/dist/src/prediction/constants.js +46 -0
- package/dist/src/prediction/fetch.d.ts +82 -0
- package/dist/src/prediction/fetch.js +270 -0
- package/dist/src/prediction/generated/bucket_v2_framework/account.d.ts +100 -0
- package/dist/src/prediction/generated/bucket_v2_framework/account.js +129 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/std/type_name.d.ts +6 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/std/type_name.js +19 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/balance.d.ts +10 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/balance.js +14 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_map.js +27 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_set.d.ts +16 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_set.js +19 -0
- package/dist/src/prediction/generated/bucket_v2_framework/double.d.ts +382 -0
- package/dist/src/prediction/generated/bucket_v2_framework/double.js +466 -0
- package/dist/src/prediction/generated/bucket_v2_framework/float.d.ts +362 -0
- package/dist/src/prediction/generated/bucket_v2_framework/float.js +440 -0
- package/dist/src/prediction/generated/bucket_v2_framework/liability.d.ts +193 -0
- package/dist/src/prediction/generated/bucket_v2_framework/liability.js +205 -0
- package/dist/src/prediction/generated/bucket_v2_framework/linked_table.d.ts +384 -0
- package/dist/src/prediction/generated/bucket_v2_framework/linked_table.js +382 -0
- package/dist/src/prediction/generated/bucket_v2_framework/sheet.d.ts +344 -0
- package/dist/src/prediction/generated/bucket_v2_framework/sheet.js +338 -0
- package/dist/src/prediction/generated/utils/index.d.ts +30 -0
- package/dist/src/prediction/generated/utils/index.js +160 -0
- package/dist/src/prediction/generated/waterx_account/account.d.ts +1589 -0
- package/dist/src/prediction/generated/waterx_account/account.js +1758 -0
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/liability.d.ts +7 -0
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/liability.js +13 -0
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/sheet.d.ts +7 -0
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/sheet.js +16 -0
- package/dist/src/prediction/generated/waterx_account/deps/std/type_name.d.ts +6 -0
- package/dist/src/prediction/generated/waterx_account/deps/std/type_name.js +19 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/balance.d.ts +10 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/balance.js +14 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/object_table.d.ts +12 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/object_table.js +19 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/table.d.ts +24 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/table.js +31 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_map.js +27 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_set.d.ts +16 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_set.js +19 -0
- package/dist/src/prediction/generated/waterx_account/direct_rule.d.ts +75 -0
- package/dist/src/prediction/generated/waterx_account/direct_rule.js +78 -0
- package/dist/src/prediction/generated/waterx_account/events.d.ts +33 -0
- package/dist/src/prediction/generated/waterx_account/events.js +137 -0
- package/dist/src/prediction/generated/waterx_account/version.d.ts +10 -0
- package/dist/src/prediction/generated/waterx_account/version.js +8 -0
- package/dist/src/prediction/generated/waterx_prediction/account_data.d.ts +327 -0
- package/dist/src/prediction/generated/waterx_prediction/account_data.js +405 -0
- package/dist/src/prediction/generated/waterx_prediction/admin.d.ts +5 -0
- package/dist/src/prediction/generated/waterx_prediction/admin.js +9 -0
- package/dist/src/prediction/generated/waterx_prediction/bet_sharing.d.ts +60 -0
- package/dist/src/prediction/generated/waterx_prediction/bet_sharing.js +83 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/bucket_v2_framework/linked_table.d.ts +8 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/bucket_v2_framework/linked_table.js +18 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/balance.d.ts +10 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/balance.js +14 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/table.d.ts +24 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/table.js +31 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/vec_set.d.ts +16 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/vec_set.js +19 -0
- package/dist/src/prediction/generated/waterx_prediction/events.d.ts +22 -0
- package/dist/src/prediction/generated/waterx_prediction/events.js +179 -0
- package/dist/src/prediction/generated/waterx_prediction/global_config.d.ts +116 -0
- package/dist/src/prediction/generated/waterx_prediction/global_config.js +141 -0
- package/dist/src/prediction/generated/waterx_prediction/order.d.ts +200 -0
- package/dist/src/prediction/generated/waterx_prediction/order.js +284 -0
- package/dist/src/prediction/generated/waterx_prediction/outcome.d.ts +58 -0
- package/dist/src/prediction/generated/waterx_prediction/outcome.js +73 -0
- package/dist/src/prediction/generated/waterx_prediction/position.d.ts +160 -0
- package/dist/src/prediction/generated/waterx_prediction/position.js +214 -0
- package/dist/src/prediction/generated/waterx_prediction/version.d.ts +10 -0
- package/dist/src/prediction/generated/waterx_prediction/version.js +8 -0
- package/dist/src/prediction/generated/waterx_prediction/view.d.ts +353 -0
- package/dist/src/prediction/generated/waterx_prediction/view.js +432 -0
- package/dist/src/prediction/generated/waterx_prediction/waterx_prediction.d.ts +1698 -0
- package/dist/src/prediction/generated/waterx_prediction/waterx_prediction.js +1733 -0
- package/dist/src/prediction/gift-link.d.ts +6 -0
- package/dist/src/prediction/gift-link.js +5 -0
- package/dist/src/prediction/gift.d.ts +223 -0
- package/dist/src/prediction/gift.js +451 -0
- package/dist/src/prediction/index.d.ts +29 -0
- package/dist/src/prediction/index.js +21 -0
- package/dist/src/prediction/prediction.d.ts +104 -0
- package/dist/src/prediction/prediction.js +317 -0
- package/dist/src/prediction/tx-builders.d.ts +44 -0
- package/dist/src/prediction/tx-builders.js +52 -0
- package/dist/src/prediction/types.d.ts +93 -0
- package/dist/src/prediction/types.js +1 -0
- package/dist/src/prediction/user/account.d.ts +2 -0
- package/dist/src/prediction/user/account.js +1 -0
- package/dist/src/prediction/user/admin.d.ts +6 -0
- package/dist/src/prediction/user/admin.js +3 -0
- package/dist/src/prediction/user/gift.d.ts +2 -0
- package/dist/src/prediction/user/gift.js +1 -0
- package/dist/src/prediction/user/index.d.ts +5 -0
- package/dist/src/prediction/user/index.js +3 -0
- package/dist/src/prediction/user/keeper.d.ts +2 -0
- package/dist/src/prediction/user/keeper.js +1 -0
- package/dist/src/prediction/user/order.d.ts +2 -0
- package/dist/src/prediction/user/order.js +1 -0
- package/dist/src/prediction/user/position.d.ts +2 -0
- package/dist/src/prediction/user/position.js +1 -0
- package/dist/src/prediction/utils/bcs.d.ts +1 -0
- package/dist/src/prediction/utils/bcs.js +1 -0
- package/dist/src/prediction/utils/index.d.ts +1 -0
- package/dist/src/prediction/utils/index.js +1 -0
- package/dist/src/prediction/utils.d.ts +30 -0
- package/dist/src/prediction/utils.js +177 -0
- package/dist/src/sdk.d.ts +18 -0
- package/dist/src/sdk.js +17 -0
- package/dist/src/tx-builders.d.ts +54 -0
- package/dist/src/tx-builders.js +141 -0
- package/dist/src/unified-client.d.ts +407 -0
- package/dist/src/unified-client.js +123 -0
- package/dist/src/user/account.d.ts +27 -0
- package/dist/src/user/account.js +34 -8
- package/dist/src/user/credit.d.ts +8 -14
- package/dist/src/user/credit.js +9 -23
- package/dist/src/user/custody.d.ts +4 -18
- package/dist/src/user/custody.js +14 -25
- package/dist/src/utils/consolidate-balance.d.ts +37 -0
- package/dist/src/utils/consolidate-balance.js +89 -0
- package/dist/src/utils/math.d.ts +86 -0
- package/dist/src/utils/math.js +100 -0
- package/dist/src/utils/pyth.d.ts +42 -7
- package/dist/src/utils/pyth.js +107 -31
- package/package.json +129 -34
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { addDelegate, allowPredictionProtocolAsset, consumeDepositDirect, createAccount, deposit, disallowPredictionProtocolAsset, removeDelegate, requestDeposit, requestDepositFromReceivings, requestWithdraw, setDelegatePredictionPermission, transferCoinToAccount, whitelistPredictionProtocol, } from "../account.ts";
|
|
2
|
+
export type { AddDelegateParams, ConsumeDepositDirectParams, CreateAccountParams, PredictionProtocolAssetParams, RemoveDelegateParams, RequestDepositFromReceivingsParams, RequestDepositParams, RequestWithdrawParams, SetDelegatePredictionPermissionParams, TransferCoinToAccountParams, WhitelistPredictionProtocolParams, } from "../account.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { addDelegate, allowPredictionProtocolAsset, consumeDepositDirect, createAccount, deposit, disallowPredictionProtocolAsset, removeDelegate, requestDeposit, requestDepositFromReceivings, requestWithdraw, setDelegatePredictionPermission, transferCoinToAccount, whitelistPredictionProtocol, } from "../account.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { adminPlaceOrderFor } from "../prediction.ts";
|
|
2
|
+
export type { AdminPlaceOrderForParams } from "../prediction.ts";
|
|
3
|
+
export { allowPredictionProtocolAsset, disallowPredictionProtocolAsset, whitelistPredictionProtocol, } from "../account.ts";
|
|
4
|
+
export type { PredictionProtocolAssetParams, WhitelistPredictionProtocolParams, } from "../account.ts";
|
|
5
|
+
export { addKeeper, adminWithdraw, createMarketRegistry, depositSettlement, pauseMarket, removeKeeper, setMinReserve, setOrderCancelCooldownMs, unpauseMarket, } from "../admin.ts";
|
|
6
|
+
export type { AdminWithdrawParams, CreateMarketRegistryParams, DepositSettlementParams, KeeperAdminParams, MarketPauseParams, SetMinReserveParams, SetOrderCancelCooldownParams, } from "../admin.ts";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { adminPlaceOrderFor } from "../prediction.js";
|
|
2
|
+
export { allowPredictionProtocolAsset, disallowPredictionProtocolAsset, whitelistPredictionProtocol, } from "../account.js";
|
|
3
|
+
export { addKeeper, adminWithdraw, createMarketRegistry, depositSettlement, pauseMarket, removeKeeper, setMinReserve, setOrderCancelCooldownMs, unpauseMarket, } from "../admin.js";
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { base64UrlNoPadDecode, base64UrlNoPadEncode, buildClaimShareFlow, buildCreateGiftFlow, buildGiftClaimMessage, claimShare, createGift, deleteGift, deriveGiftAddress, deriveGiftKeypair, encodeGiftUrl, generateGiftSeed, getCreatorGiftCount, getCreatorGiftIds, getGift, getGiftConfigPaused, getGiftControllerAddress, getGiftHasClaimed, parseGiftUrl, signGiftClaim, } from "../gift.ts";
|
|
2
|
+
export type { BuildClaimShareFlowParams, BuildClaimShareFlowResult, BuildCreateGiftFlowResult, ClaimShareParams, CreateGiftParams, DeleteGiftParams, GiftBaseParams, GiftReferralParams, GiftUrlParts, GiftView, } from "../gift.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { base64UrlNoPadDecode, base64UrlNoPadEncode, buildClaimShareFlow, buildCreateGiftFlow, buildGiftClaimMessage, claimShare, createGift, deleteGift, deriveGiftAddress, deriveGiftKeypair, encodeGiftUrl, generateGiftSeed, getCreatorGiftCount, getCreatorGiftIds, getGift, getGiftConfigPaused, getGiftControllerAddress, getGiftHasClaimed, parseGiftUrl, signGiftClaim, } from "../gift.js";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { addDelegate, consumeDepositDirect, createAccount, deposit, removeDelegate, requestDeposit, requestDepositFromReceivings, requestWithdraw, setDelegatePredictionPermission, transferCoinToAccount, whitelistPredictionProtocol, } from "../account.ts";
|
|
2
|
+
export type { AddDelegateParams, ConsumeDepositDirectParams, CreateAccountParams, RemoveDelegateParams, RequestDepositFromReceivingsParams, RequestDepositParams, RequestWithdrawParams, SetDelegatePredictionPermissionParams, TransferCoinToAccountParams, WhitelistPredictionProtocolParams, } from "../account.ts";
|
|
3
|
+
export { batchClaim, claim, placeOrder, requestClose, selectionArg, selfCancelClose, selfCancelOrder, } from "../prediction.ts";
|
|
4
|
+
export type { BatchClaimParams, ClaimParams, PlaceOrderParams, RequestCloseParams, SelfCancelCloseParams, SelfCancelOrderParams, } from "../prediction.ts";
|
|
5
|
+
export * as gift from "./gift.ts";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { addDelegate, consumeDepositDirect, createAccount, deposit, removeDelegate, requestDeposit, requestDepositFromReceivings, requestWithdraw, setDelegatePredictionPermission, transferCoinToAccount, whitelistPredictionProtocol, } from "../account.js";
|
|
2
|
+
export { batchClaim, claim, placeOrder, requestClose, selectionArg, selfCancelClose, selfCancelOrder, } from "../prediction.js";
|
|
3
|
+
export * as gift from "./gift.js";
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { batchForceClaim, buildBatchForceClaimTransactions, cancelClose, cancelOrder, confirmClose, fillOrder, forceClaim, outcomeArg, resolveMarket, } from "../prediction.ts";
|
|
2
|
+
export type { BatchForceClaimParams, BuildBatchForceClaimTransactionsParams, CancelCloseParams, CancelOrderParams, ConfirmCloseParams, FillOrderParams, ForceClaimParams, ResolveMarketParams, } from "../prediction.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { batchForceClaim, buildBatchForceClaimTransactions, cancelClose, cancelOrder, confirmClose, fillOrder, forceClaim, outcomeArg, resolveMarket, } from "../prediction.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { placeOrder, selfCancelOrder } from "../prediction.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { batchClaim, claim, requestClose, selfCancelClose } from "../prediction.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AccountDataViewBcs, MarketViewBcs, OrderKindBcs, OrderViewBcs, OutcomeBcs, PositionViewBcs, RegistryViewBcs, SelectionBcs, StatusBcs, decodeEnumVariant, mapAccountDataView, mapCursorView, mapMarketView, mapOrderKind, mapOrderView, mapOutcome, mapPositionView, mapRegistryView, mapSelection, mapStatus, } from "../bcs.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { AccountDataViewBcs, MarketViewBcs, OrderKindBcs, OrderViewBcs, OutcomeBcs, PositionViewBcs, RegistryViewBcs, SelectionBcs, StatusBcs, decodeEnumVariant, mapAccountDataView, mapCursorView, mapMarketView, mapOrderKind, mapOrderView, mapOutcome, mapPositionView, mapRegistryView, mapSelection, mapStatus, } from "../bcs.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { assertOutcome, assertSelection, assertU64, bytesToHex, clockArg, createAccountRequest, marketIdArg, marketIdBytesFromUnknown, normalizeMarketId, objectArg, optionU64, receivingCoinArg, requireConfig, resolveAccountPackageId, resolveAccountRegistry, resolveGlobalConfig, resolveMarketRegistry, resolvePackageId, resolveSettlementCoinType, toBigInt, } from "../utils.ts";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { assertOutcome, assertSelection, assertU64, bytesToHex, clockArg, createAccountRequest, marketIdArg, marketIdBytesFromUnknown, normalizeMarketId, objectArg, optionU64, receivingCoinArg, requireConfig, resolveAccountPackageId, resolveAccountRegistry, resolveGlobalConfig, resolveMarketRegistry, resolvePackageId, resolveSettlementCoinType, toBigInt, } from "../utils.js";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Transaction, type TransactionArgument, type TransactionObjectArgument } from "@mysten/sui/transactions";
|
|
2
|
+
import type { PredictClient } from "./client.ts";
|
|
3
|
+
import type { AccountIdentityParams, IdArgument, MarketIdInput, ObjectArgument, Outcome, Selection } from "./types.ts";
|
|
4
|
+
export declare function assertSelection(value: string): Selection;
|
|
5
|
+
export declare function assertOutcome(value: string): Outcome;
|
|
6
|
+
export declare function requireConfig<T>(value: T | undefined, name: string): T;
|
|
7
|
+
export declare function resolvePackageId(client: PredictClient, packageId?: string): string;
|
|
8
|
+
export declare function resolveAccountPackageId(client: PredictClient, accountPackageId?: string): string;
|
|
9
|
+
export declare function resolveSettlementCoinType(client: PredictClient, coinType?: string): string;
|
|
10
|
+
export declare function resolveMarketRegistry(client: PredictClient, marketRegistry?: string): string;
|
|
11
|
+
export declare function resolveAccountRegistry(client: PredictClient, accountRegistry?: string): string;
|
|
12
|
+
export declare function resolveGlobalConfig(client: PredictClient, globalConfig?: string): string;
|
|
13
|
+
/** Ensures `value` is a valid unsigned 64-bit integer. */
|
|
14
|
+
export declare function assertU64(value: bigint, name?: string): bigint;
|
|
15
|
+
export declare function toBigInt(value: bigint | number | string): bigint;
|
|
16
|
+
export declare function objectArg(tx: Transaction, value: ObjectArgument): TransactionArgument;
|
|
17
|
+
export declare function idArg(tx: Transaction, value: IdArgument): TransactionArgument;
|
|
18
|
+
export declare function clockArg(tx: Transaction): TransactionArgument;
|
|
19
|
+
export declare function createAccountRequest(client: PredictClient, tx: Transaction, params?: AccountIdentityParams): TransactionArgument;
|
|
20
|
+
/** Coerces on-chain `vector<u8>` shapes used in view decoding. */
|
|
21
|
+
export declare function marketIdBytesFromUnknown(raw: unknown): Uint8Array;
|
|
22
|
+
export declare function normalizeMarketId(marketId: MarketIdInput): Uint8Array;
|
|
23
|
+
export declare function marketIdArg(tx: Transaction, marketId: MarketIdInput): TransactionArgument;
|
|
24
|
+
export declare function bytesToHex(bytes: Uint8Array | number[]): string;
|
|
25
|
+
export declare function optionU64(value: bigint | number | string | null | undefined): TransactionArgument;
|
|
26
|
+
export declare function receivingCoinArg(tx: Transaction, coin: {
|
|
27
|
+
objectId: string;
|
|
28
|
+
version: string | bigint | number;
|
|
29
|
+
digest: string;
|
|
30
|
+
}): TransactionObjectArgument;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { CLOCK_OBJECT_ID } from "./constants.js";
|
|
2
|
+
const SELECTIONS = ["YES", "NO"];
|
|
3
|
+
const OUTCOMES = ["YES", "NO", "INVALID"];
|
|
4
|
+
const U64_MAX = (1n << 64n) - 1n;
|
|
5
|
+
export function assertSelection(value) {
|
|
6
|
+
if (SELECTIONS.includes(value))
|
|
7
|
+
return value;
|
|
8
|
+
throw new Error(`Invalid Selection: expected "YES" or "NO", got ${JSON.stringify(value)}`);
|
|
9
|
+
}
|
|
10
|
+
export function assertOutcome(value) {
|
|
11
|
+
if (OUTCOMES.includes(value))
|
|
12
|
+
return value;
|
|
13
|
+
throw new Error(`Invalid Outcome: expected "YES", "NO", or "INVALID", got ${JSON.stringify(value)}`);
|
|
14
|
+
}
|
|
15
|
+
export function requireConfig(value, name) {
|
|
16
|
+
if (value === undefined || value === null || value === "") {
|
|
17
|
+
throw new Error(`${name} is required. Pass it in params or PredictClient config.`);
|
|
18
|
+
}
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
function resolveOptionalString(override, fallback) {
|
|
22
|
+
if (override === undefined || override === "")
|
|
23
|
+
return fallback;
|
|
24
|
+
return override;
|
|
25
|
+
}
|
|
26
|
+
export function resolvePackageId(client, packageId) {
|
|
27
|
+
return resolveOptionalString(packageId, client.packageId());
|
|
28
|
+
}
|
|
29
|
+
export function resolveAccountPackageId(client, accountPackageId) {
|
|
30
|
+
return resolveOptionalString(accountPackageId, client.waterxAccountPackageId());
|
|
31
|
+
}
|
|
32
|
+
export function resolveSettlementCoinType(client, coinType) {
|
|
33
|
+
return resolveOptionalString(coinType, client.settlementCoinType());
|
|
34
|
+
}
|
|
35
|
+
export function resolveMarketRegistry(client, marketRegistry) {
|
|
36
|
+
return marketRegistry === undefined || marketRegistry === ""
|
|
37
|
+
? client.marketRegistry()
|
|
38
|
+
: marketRegistry;
|
|
39
|
+
}
|
|
40
|
+
export function resolveAccountRegistry(client, accountRegistry) {
|
|
41
|
+
return accountRegistry === undefined || accountRegistry === ""
|
|
42
|
+
? client.accountRegistry()
|
|
43
|
+
: accountRegistry;
|
|
44
|
+
}
|
|
45
|
+
export function resolveGlobalConfig(client, globalConfig) {
|
|
46
|
+
return globalConfig === undefined || globalConfig === "" ? client.globalConfigId() : globalConfig;
|
|
47
|
+
}
|
|
48
|
+
/** Ensures `value` is a valid unsigned 64-bit integer. */
|
|
49
|
+
export function assertU64(value, name = "value") {
|
|
50
|
+
if (value < 0n) {
|
|
51
|
+
throw new Error(`${name} must be non-negative, got ${value}`);
|
|
52
|
+
}
|
|
53
|
+
if (value > U64_MAX) {
|
|
54
|
+
throw new Error(`${name} exceeds u64 max (${U64_MAX}), got ${value}`);
|
|
55
|
+
}
|
|
56
|
+
return value;
|
|
57
|
+
}
|
|
58
|
+
export function toBigInt(value) {
|
|
59
|
+
if (typeof value === "bigint") {
|
|
60
|
+
return assertU64(value);
|
|
61
|
+
}
|
|
62
|
+
if (typeof value === "number") {
|
|
63
|
+
if (!Number.isInteger(value)) {
|
|
64
|
+
throw new Error(`Invalid integer: ${value}`);
|
|
65
|
+
}
|
|
66
|
+
return assertU64(BigInt(value));
|
|
67
|
+
}
|
|
68
|
+
const trimmed = value.trim();
|
|
69
|
+
if (trimmed === "") {
|
|
70
|
+
throw new Error("Invalid integer: empty string");
|
|
71
|
+
}
|
|
72
|
+
if (!/^\d+$/.test(trimmed)) {
|
|
73
|
+
throw new Error(`Invalid integer: ${JSON.stringify(value)}`);
|
|
74
|
+
}
|
|
75
|
+
return assertU64(BigInt(trimmed));
|
|
76
|
+
}
|
|
77
|
+
export function objectArg(tx, value) {
|
|
78
|
+
return typeof value === "string" ? tx.object(value) : value;
|
|
79
|
+
}
|
|
80
|
+
export function idArg(tx, value) {
|
|
81
|
+
return typeof value === "string" ? tx.pure.id(value) : value;
|
|
82
|
+
}
|
|
83
|
+
export function clockArg(tx) {
|
|
84
|
+
return tx.object.clock ? tx.object.clock() : tx.object(CLOCK_OBJECT_ID);
|
|
85
|
+
}
|
|
86
|
+
export function createAccountRequest(client, tx, params = {}) {
|
|
87
|
+
const pkg = client.bucketFrameworkPackageId();
|
|
88
|
+
if (params.bucketAccount === undefined) {
|
|
89
|
+
const [request] = tx.moveCall({
|
|
90
|
+
target: `${pkg}::account::request`,
|
|
91
|
+
});
|
|
92
|
+
return request;
|
|
93
|
+
}
|
|
94
|
+
const [request] = tx.moveCall({
|
|
95
|
+
target: `${pkg}::account::request_with_account`,
|
|
96
|
+
arguments: [objectArg(tx, params.bucketAccount)],
|
|
97
|
+
});
|
|
98
|
+
return request;
|
|
99
|
+
}
|
|
100
|
+
/** Coerces on-chain `vector<u8>` shapes used in view decoding. */
|
|
101
|
+
export function marketIdBytesFromUnknown(raw) {
|
|
102
|
+
if (raw instanceof Uint8Array)
|
|
103
|
+
return raw;
|
|
104
|
+
if (Array.isArray(raw))
|
|
105
|
+
return bytesFromNumberArray(raw);
|
|
106
|
+
if (typeof raw === "string") {
|
|
107
|
+
throw new Error("market_id from chain views must be Uint8Array or number[]; strings are not supported. " +
|
|
108
|
+
"Use normalizeMarketId() when building PTBs from string market ids.");
|
|
109
|
+
}
|
|
110
|
+
throw new Error(`market_id must be Uint8Array or number[], got ${typeof raw}`);
|
|
111
|
+
}
|
|
112
|
+
function bytesFromNumberArray(marketId) {
|
|
113
|
+
const bytes = new Uint8Array(marketId.length);
|
|
114
|
+
for (let i = 0; i < marketId.length; i += 1) {
|
|
115
|
+
const byte = marketId[i];
|
|
116
|
+
if (!Number.isInteger(byte) || byte < 0 || byte > 255) {
|
|
117
|
+
throw new Error(`Invalid market id byte at index ${i}: ${byte} (expected 0-255)`);
|
|
118
|
+
}
|
|
119
|
+
bytes[i] = byte;
|
|
120
|
+
}
|
|
121
|
+
return bytes;
|
|
122
|
+
}
|
|
123
|
+
function parseHexMarketId(marketId) {
|
|
124
|
+
const hex = marketId.slice(2);
|
|
125
|
+
if (hex.length === 0) {
|
|
126
|
+
throw new Error(`Invalid hex market id: empty hex (${marketId})`);
|
|
127
|
+
}
|
|
128
|
+
if (hex.length % 2 !== 0) {
|
|
129
|
+
throw new Error(`Invalid hex market id: ${marketId}`);
|
|
130
|
+
}
|
|
131
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
132
|
+
for (let i = 0; i < bytes.length; i += 1) {
|
|
133
|
+
const pair = hex.slice(i * 2, i * 2 + 2);
|
|
134
|
+
if (!/^[0-9a-fA-F]{2}$/.test(pair)) {
|
|
135
|
+
throw new Error(`Invalid hex market id: bad nibble pair ${JSON.stringify(pair)} in ${marketId}`);
|
|
136
|
+
}
|
|
137
|
+
bytes[i] = Number.parseInt(pair, 16);
|
|
138
|
+
}
|
|
139
|
+
return bytes;
|
|
140
|
+
}
|
|
141
|
+
export function normalizeMarketId(marketId) {
|
|
142
|
+
if (marketId instanceof Uint8Array)
|
|
143
|
+
return marketId;
|
|
144
|
+
if (Array.isArray(marketId))
|
|
145
|
+
return bytesFromNumberArray(marketId);
|
|
146
|
+
if (marketId.startsWith("0x") || marketId.startsWith("0X")) {
|
|
147
|
+
return parseHexMarketId(marketId);
|
|
148
|
+
}
|
|
149
|
+
return new TextEncoder().encode(marketId);
|
|
150
|
+
}
|
|
151
|
+
export function marketIdArg(tx, marketId) {
|
|
152
|
+
return tx.pure.vector("u8", Array.from(normalizeMarketId(marketId)));
|
|
153
|
+
}
|
|
154
|
+
export function bytesToHex(bytes) {
|
|
155
|
+
const normalized = bytes instanceof Uint8Array ? bytes : bytesFromNumberArray(bytes);
|
|
156
|
+
return `0x${Array.from(normalized, (b) => b.toString(16).padStart(2, "0")).join("")}`;
|
|
157
|
+
}
|
|
158
|
+
export function optionU64(value) {
|
|
159
|
+
return (tx) => tx.pure.option("u64", value == null ? null : toBigInt(value));
|
|
160
|
+
}
|
|
161
|
+
function formatObjectVersion(version) {
|
|
162
|
+
if (typeof version === "string") {
|
|
163
|
+
const trimmed = version.trim();
|
|
164
|
+
if (trimmed === "" || !/^\d+$/.test(trimmed)) {
|
|
165
|
+
throw new Error(`Invalid object version: ${JSON.stringify(version)}`);
|
|
166
|
+
}
|
|
167
|
+
return trimmed;
|
|
168
|
+
}
|
|
169
|
+
return String(toBigInt(version));
|
|
170
|
+
}
|
|
171
|
+
export function receivingCoinArg(tx, coin) {
|
|
172
|
+
return tx.receivingRef({
|
|
173
|
+
objectId: coin.objectId,
|
|
174
|
+
version: formatObjectVersion(coin.version),
|
|
175
|
+
digest: coin.digest,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package root for `@waterx/sdk` (`.` export).
|
|
3
|
+
*
|
|
4
|
+
* - `Client` — the unified facade (`client.perp.*` / `client.predict.*`).
|
|
5
|
+
* - `perp` / `prediction` — namespaces exposing each line's full API; use these
|
|
6
|
+
* to disambiguate the builder names that collide across the two lines.
|
|
7
|
+
* - The flat re-export below preserves the legacy `@waterx/perp-sdk` surface at
|
|
8
|
+
* the package root for one major cycle (DEPRECATED — removed next major).
|
|
9
|
+
*
|
|
10
|
+
* Prediction is reachable only via the `prediction` namespace / `@waterx/sdk/prediction`
|
|
11
|
+
* (never flat at the root) because its builder names collide with perp's.
|
|
12
|
+
*/
|
|
13
|
+
export { Client } from "./unified-client.ts";
|
|
14
|
+
export type { ClientCreateOptions, PerpModule, PredictModule } from "./unified-client.ts";
|
|
15
|
+
export type { BuildBatchClaimTxParams as BuildPredictBatchClaimTxParams, BuildPlaceOrderTxParams as BuildPredictPlaceOrderTxParams, } from "./prediction/tx-builders.ts";
|
|
16
|
+
export * as perp from "./index.ts";
|
|
17
|
+
export * as prediction from "./prediction/index.ts";
|
|
18
|
+
export * from "./index.ts";
|
package/dist/src/sdk.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Package root for `@waterx/sdk` (`.` export).
|
|
3
|
+
*
|
|
4
|
+
* - `Client` — the unified facade (`client.perp.*` / `client.predict.*`).
|
|
5
|
+
* - `perp` / `prediction` — namespaces exposing each line's full API; use these
|
|
6
|
+
* to disambiguate the builder names that collide across the two lines.
|
|
7
|
+
* - The flat re-export below preserves the legacy `@waterx/perp-sdk` surface at
|
|
8
|
+
* the package root for one major cycle (DEPRECATED — removed next major).
|
|
9
|
+
*
|
|
10
|
+
* Prediction is reachable only via the `prediction` namespace / `@waterx/sdk/prediction`
|
|
11
|
+
* (never flat at the root) because its builder names collide with perp's.
|
|
12
|
+
*/
|
|
13
|
+
export { Client } from "./unified-client.js";
|
|
14
|
+
export * as perp from "./index.js";
|
|
15
|
+
export * as prediction from "./prediction/index.js";
|
|
16
|
+
// DEPRECATED flat perp surface (migration aid from `@waterx/perp-sdk`).
|
|
17
|
+
export * from "./index.js";
|
|
@@ -38,7 +38,61 @@ export interface CommonBuildOpts {
|
|
|
38
38
|
* Pass `false` only when the market checklist is empty.
|
|
39
39
|
*/
|
|
40
40
|
useSponsor?: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Pre-sweep parked backing assets (USDC, USDsui, …) at the wxa account's
|
|
43
|
+
* address into USD credit, plus any CREDIT coins/funds at the address into
|
|
44
|
+
* the internal wxa slot — see {@link appendConsolidateForSpend}. Skips empty
|
|
45
|
+
* buckets via gRPC probes so it's safe on any account.
|
|
46
|
+
*
|
|
47
|
+
* Default: `true`. Set to `false` to skip (e.g. caller already swept,
|
|
48
|
+
* deployment lacks `native_custody`, or the gRPC reads aren't worth
|
|
49
|
+
* the latency).
|
|
50
|
+
*
|
|
51
|
+
* Each enabled call adds 2 gRPC reads per configured backing asset
|
|
52
|
+
* (`getBalance` + `listCoins`).
|
|
53
|
+
*
|
|
54
|
+
* Only honored by async builders (this is an async sweep). Sync
|
|
55
|
+
* builders never auto-prepend the sweep — for those, call
|
|
56
|
+
* {@link buildConsolidateToUsdTx} separately.
|
|
57
|
+
*/
|
|
58
|
+
consolidateToUsd?: boolean;
|
|
41
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* For every backing asset registered on `native_custody`, append two drain
|
|
62
|
+
* legs to `tx`:
|
|
63
|
+
*
|
|
64
|
+
* `requestDepositFromFunds<T>` → `mintCreditFromRequest<T, USD>` → `consumeDepositDirect<USD>`
|
|
65
|
+
* `requestDepositFromReceivings<T>` → `mintCreditFromRequest<T, USD>` → `consumeDepositDirect<USD>`
|
|
66
|
+
*
|
|
67
|
+
* Empty legs are skipped — the on-chain `mint` rejects zero-amount deposits.
|
|
68
|
+
* Returns the number of drain legs added (useful for logging / early-out).
|
|
69
|
+
*
|
|
70
|
+
* Silently no-ops when `native_custody` / `waterx_credit` aren't configured
|
|
71
|
+
* for the loaded deployment.
|
|
72
|
+
*/
|
|
73
|
+
export declare function appendConsolidateToUsd(client: WaterXClient, tx: Transaction, accountId: string): Promise<number>;
|
|
74
|
+
/**
|
|
75
|
+
* Drain CREDIT parked at `accountId`'s Sui address (funds accumulator +
|
|
76
|
+
* owned `Coin<CREDIT>`) into the wxa internal slot via
|
|
77
|
+
* `consumeDepositDirect<CREDIT>`. Complements {@link appendConsolidateToUsd}
|
|
78
|
+
* for address-owned wxUSD that predict / perp actions debit from the internal
|
|
79
|
+
* balance.
|
|
80
|
+
*/
|
|
81
|
+
export declare function appendConsolidateAddressCredit(client: WaterXClient, tx: Transaction, accountId: string): Promise<number>;
|
|
82
|
+
/**
|
|
83
|
+
* Full pre-action sweep: backing assets → wxUSD credit (PSM) plus address
|
|
84
|
+
* CREDIT → internal slot. Used by async tx-builders when `consolidateToUsd`
|
|
85
|
+
* is enabled (default).
|
|
86
|
+
*/
|
|
87
|
+
export declare function appendConsolidateForSpend(client: WaterXClient, tx: Transaction, accountId: string): Promise<number>;
|
|
88
|
+
/**
|
|
89
|
+
* Standalone PTB that drains every backing asset parked at the account's
|
|
90
|
+
* address into USD credit under the account — see {@link appendConsolidateToUsd}.
|
|
91
|
+
*
|
|
92
|
+
* Returns an empty `Transaction` when nothing is parked. Callers can
|
|
93
|
+
* `client.simulate(tx)` to detect a no-op before submitting.
|
|
94
|
+
*/
|
|
95
|
+
export declare function buildConsolidateToUsdTx(client: WaterXClient, accountId: string, tx?: Transaction): Promise<Transaction>;
|
|
42
96
|
export interface BuildClosePositionParams extends ClosePositionRequestParams, CommonBuildOpts {
|
|
43
97
|
collateralTicker?: string;
|
|
44
98
|
}
|
package/dist/src/tx-builders.js
CHANGED
|
@@ -14,12 +14,16 @@
|
|
|
14
14
|
* 5. Executes the trading request via `trading::execute`.
|
|
15
15
|
*/
|
|
16
16
|
import { Transaction } from "@mysten/sui/transactions";
|
|
17
|
+
import { consumeDepositDirect } from "./generated/waterx_account/direct_rule.js";
|
|
18
|
+
import { requestDepositFromFunds, requestDepositFromReceivings } from "./user/account.js";
|
|
17
19
|
import { consumeCreditDeposit, enqueueWithdrawal, executeWithdrawalNative, executeWithdrawalWormhole, redeemVaa, requestCreditWithdraw, routeNative, routeWormhole, } from "./user/credit.js";
|
|
20
|
+
import { mintCreditFromRequest } from "./user/custody.js";
|
|
18
21
|
import { addPreOrderRequest, cancelOrderRequest, cancelPreOrderRequest, placeOrderRequest, updateOrderRequest, } from "./user/order.js";
|
|
19
22
|
import { claimReward, stake, unstake } from "./user/staking.js";
|
|
20
23
|
import { closePositionRequest, decreasePositionRequest, depositCollateralRequest, executeTrading, increasePositionRequest, withdrawCollateralRequest, } from "./user/trading.js";
|
|
21
24
|
import { cancelRedeemWlp, mintWlp, requestRedeemWlp, updateTokenValue, } from "./user/wlp.js";
|
|
22
25
|
import { getCollateralAssets } from "./utils/config.js";
|
|
26
|
+
import { probeAddressCreditBalance, probeParkedBackingAssets, } from "./utils/consolidate-balance.js";
|
|
23
27
|
import { openPythSponsorFund, PythCache, refreshOraclePrices, reimbursePythSponsor, updatePythPrices, } from "./utils/pyth.js";
|
|
24
28
|
function newTx(opts) {
|
|
25
29
|
return opts?.tx ?? new Transaction();
|
|
@@ -51,6 +55,7 @@ async function refreshWlpPoolOracles(tx, client, extraTickers, opts) {
|
|
|
51
55
|
* trading::execute(req)
|
|
52
56
|
*/
|
|
53
57
|
async function wrapRequestAndExecute(client, tx, req, collateralTicker, opts, buildRequest) {
|
|
58
|
+
await maybeConsolidate(client, tx, req.accountId, opts);
|
|
54
59
|
const useSponsor = opts?.useSponsor ?? true;
|
|
55
60
|
let sponsorFund;
|
|
56
61
|
if (useSponsor)
|
|
@@ -73,6 +78,139 @@ async function wrapRequestAndExecute(client, tx, req, collateralTicker, opts, bu
|
|
|
73
78
|
request: tradingReq,
|
|
74
79
|
});
|
|
75
80
|
}
|
|
81
|
+
// ============================================================================
|
|
82
|
+
// Consolidate parked backing assets → USD credit (pre-action sweep)
|
|
83
|
+
// ============================================================================
|
|
84
|
+
/**
|
|
85
|
+
* For every backing asset registered on `native_custody`, append two drain
|
|
86
|
+
* legs to `tx`:
|
|
87
|
+
*
|
|
88
|
+
* `requestDepositFromFunds<T>` → `mintCreditFromRequest<T, USD>` → `consumeDepositDirect<USD>`
|
|
89
|
+
* `requestDepositFromReceivings<T>` → `mintCreditFromRequest<T, USD>` → `consumeDepositDirect<USD>`
|
|
90
|
+
*
|
|
91
|
+
* Empty legs are skipped — the on-chain `mint` rejects zero-amount deposits.
|
|
92
|
+
* Returns the number of drain legs added (useful for logging / early-out).
|
|
93
|
+
*
|
|
94
|
+
* Silently no-ops when `native_custody` / `waterx_credit` aren't configured
|
|
95
|
+
* for the loaded deployment.
|
|
96
|
+
*/
|
|
97
|
+
export async function appendConsolidateToUsd(client, tx, accountId) {
|
|
98
|
+
const parked = await probeParkedBackingAssets(client, accountId);
|
|
99
|
+
let legs = 0;
|
|
100
|
+
for (const row of parked) {
|
|
101
|
+
if (row.fundsRaw > 0n) {
|
|
102
|
+
const fromFunds = requestDepositFromFunds(client, tx, {
|
|
103
|
+
accountId,
|
|
104
|
+
coinType: row.assetType,
|
|
105
|
+
});
|
|
106
|
+
foldDepositRequestToUsd(client, tx, fromFunds, row.assetType);
|
|
107
|
+
legs += 1;
|
|
108
|
+
}
|
|
109
|
+
if (row.coinsRaw > 0n) {
|
|
110
|
+
const coins = (await client.listCoins({
|
|
111
|
+
owner: accountId,
|
|
112
|
+
coinType: row.assetType,
|
|
113
|
+
}));
|
|
114
|
+
const refs = (coins.objects ?? []).filter((c) => !!c.objectId && !!c.version && !!c.digest);
|
|
115
|
+
if (refs.length === 0)
|
|
116
|
+
continue;
|
|
117
|
+
const receivings = refs.map((c) => tx.receivingRef({ objectId: c.objectId, version: c.version, digest: c.digest }));
|
|
118
|
+
const fromReceivings = requestDepositFromReceivings(client, tx, {
|
|
119
|
+
accountId,
|
|
120
|
+
coinType: row.assetType,
|
|
121
|
+
receivings,
|
|
122
|
+
});
|
|
123
|
+
foldDepositRequestToUsd(client, tx, fromReceivings, row.assetType);
|
|
124
|
+
legs += 1;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return legs;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Drain CREDIT parked at `accountId`'s Sui address (funds accumulator +
|
|
131
|
+
* owned `Coin<CREDIT>`) into the wxa internal slot via
|
|
132
|
+
* `consumeDepositDirect<CREDIT>`. Complements {@link appendConsolidateToUsd}
|
|
133
|
+
* for address-owned wxUSD that predict / perp actions debit from the internal
|
|
134
|
+
* balance.
|
|
135
|
+
*/
|
|
136
|
+
export async function appendConsolidateAddressCredit(client, tx, accountId) {
|
|
137
|
+
if (!client.config.packages.waterx_credit?.credit_type)
|
|
138
|
+
return 0;
|
|
139
|
+
const creditType = client.creditType();
|
|
140
|
+
const { fundsRaw, coinsRaw } = await probeAddressCreditBalance(client, accountId);
|
|
141
|
+
let legs = 0;
|
|
142
|
+
if (fundsRaw > 0n) {
|
|
143
|
+
const fromFunds = requestDepositFromFunds(client, tx, {
|
|
144
|
+
accountId,
|
|
145
|
+
coinType: creditType,
|
|
146
|
+
});
|
|
147
|
+
consumeDepositRequest(client, tx, fromFunds, creditType);
|
|
148
|
+
legs += 1;
|
|
149
|
+
}
|
|
150
|
+
if (coinsRaw > 0n) {
|
|
151
|
+
const coins = (await client.listCoins({
|
|
152
|
+
owner: accountId,
|
|
153
|
+
coinType: creditType,
|
|
154
|
+
}));
|
|
155
|
+
const refs = (coins.objects ?? []).filter((c) => !!c.objectId && !!c.version && !!c.digest);
|
|
156
|
+
if (refs.length > 0) {
|
|
157
|
+
const receivings = refs.map((c) => tx.receivingRef({ objectId: c.objectId, version: c.version, digest: c.digest }));
|
|
158
|
+
const fromReceivings = requestDepositFromReceivings(client, tx, {
|
|
159
|
+
accountId,
|
|
160
|
+
coinType: creditType,
|
|
161
|
+
receivings,
|
|
162
|
+
});
|
|
163
|
+
consumeDepositRequest(client, tx, fromReceivings, creditType);
|
|
164
|
+
legs += 1;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return legs;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Full pre-action sweep: backing assets → wxUSD credit (PSM) plus address
|
|
171
|
+
* CREDIT → internal slot. Used by async tx-builders when `consolidateToUsd`
|
|
172
|
+
* is enabled (default).
|
|
173
|
+
*/
|
|
174
|
+
export async function appendConsolidateForSpend(client, tx, accountId) {
|
|
175
|
+
const backingLegs = await appendConsolidateToUsd(client, tx, accountId);
|
|
176
|
+
const creditLegs = await appendConsolidateAddressCredit(client, tx, accountId);
|
|
177
|
+
return backingLegs + creditLegs;
|
|
178
|
+
}
|
|
179
|
+
function consumeDepositRequest(client, tx, depositRequest, coinType) {
|
|
180
|
+
consumeDepositDirect({
|
|
181
|
+
package: client.config.packages.waterx_account.published_at,
|
|
182
|
+
arguments: {
|
|
183
|
+
registry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
184
|
+
req: depositRequest,
|
|
185
|
+
},
|
|
186
|
+
typeArguments: [coinType],
|
|
187
|
+
})(tx);
|
|
188
|
+
}
|
|
189
|
+
function foldDepositRequestToUsd(client, tx, depositRequest, assetType) {
|
|
190
|
+
const usdReq = mintCreditFromRequest(client, tx, {
|
|
191
|
+
depositRequest,
|
|
192
|
+
assetType,
|
|
193
|
+
});
|
|
194
|
+
consumeDepositRequest(client, tx, usdReq, client.creditType());
|
|
195
|
+
}
|
|
196
|
+
/** Internal: run the async sweep iff `consolidateToUsd !== false`. */
|
|
197
|
+
async function maybeConsolidate(client, tx, accountId, opts) {
|
|
198
|
+
if (opts?.consolidateToUsd === false)
|
|
199
|
+
return;
|
|
200
|
+
await appendConsolidateForSpend(client, tx, accountId);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Standalone PTB that drains every backing asset parked at the account's
|
|
204
|
+
* address into USD credit under the account — see {@link appendConsolidateToUsd}.
|
|
205
|
+
*
|
|
206
|
+
* Returns an empty `Transaction` when nothing is parked. Callers can
|
|
207
|
+
* `client.simulate(tx)` to detect a no-op before submitting.
|
|
208
|
+
*/
|
|
209
|
+
export async function buildConsolidateToUsdTx(client, accountId, tx) {
|
|
210
|
+
const txOut = tx ?? new Transaction();
|
|
211
|
+
await appendConsolidateToUsd(client, txOut, accountId);
|
|
212
|
+
return txOut;
|
|
213
|
+
}
|
|
76
214
|
export async function buildClosePositionTx(client, params) {
|
|
77
215
|
const tx = newTx(params);
|
|
78
216
|
await wrapRequestAndExecute(client, tx, params, params.collateralTicker ?? "USDCUSD", params, () => closePositionRequest(client, tx, params));
|
|
@@ -135,6 +273,7 @@ export async function buildAddPreOrderTx(client, params) {
|
|
|
135
273
|
*/
|
|
136
274
|
export async function buildMintWlpTx(client, params) {
|
|
137
275
|
const tx = newTx(params);
|
|
276
|
+
await maybeConsolidate(client, tx, params.accountId, params);
|
|
138
277
|
if (!params.skipOraclePriceRefresh) {
|
|
139
278
|
await refreshWlpPoolOracles(tx, client, [params.depositTicker], {
|
|
140
279
|
cache: params.pythCache,
|
|
@@ -155,6 +294,7 @@ export async function buildMintWlpTx(client, params) {
|
|
|
155
294
|
*/
|
|
156
295
|
export async function buildMintAndStakeWlpTx(client, params) {
|
|
157
296
|
const tx = newTx(params);
|
|
297
|
+
await maybeConsolidate(client, tx, params.accountId, params);
|
|
158
298
|
if (!params.skipOraclePriceRefresh) {
|
|
159
299
|
await refreshWlpPoolOracles(tx, client, [params.depositTicker], {
|
|
160
300
|
cache: params.pythCache,
|
|
@@ -185,6 +325,7 @@ export async function buildMintAndStakeWlpTx(client, params) {
|
|
|
185
325
|
export async function buildUnstakeAndRequestRedeemWlpTx(client, params) {
|
|
186
326
|
const tx = newTx(params);
|
|
187
327
|
const stakeAlias = params.stakeAlias ?? "WLP";
|
|
328
|
+
await maybeConsolidate(client, tx, params.accountId, params);
|
|
188
329
|
if (!params.skipOraclePriceRefresh) {
|
|
189
330
|
await refreshWlpPoolOracles(tx, client, [], {
|
|
190
331
|
cache: params.pythCache,
|