@waterx/sdk 2.4.1 → 3.0.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 +25 -21
- package/dist/src/{utils → account}/account-request.d.ts +2 -2
- package/dist/src/{user → account}/account.d.ts +23 -21
- package/dist/src/{user → account}/account.js +5 -5
- package/dist/src/account/client.d.ts +42 -0
- package/dist/src/account/client.js +17 -0
- package/dist/src/account/config.d.ts +151 -0
- package/dist/src/account/config.js +8 -0
- package/dist/src/account/constants.d.ts +5 -0
- package/dist/src/account/constants.js +5 -0
- package/dist/src/account/fetch/referral.d.ts +15 -0
- package/dist/src/account/fetch/referral.js +51 -0
- package/dist/src/account/fetch/simulate.d.ts +34 -0
- package/dist/src/account/fetch/simulate.js +43 -0
- package/dist/src/{utils/consolidate-balance.d.ts → account/funding/balance.d.ts} +3 -8
- package/dist/src/{utils/consolidate-balance.js → account/funding/balance.js} +6 -1
- package/dist/src/account/funding/consolidate.d.ts +46 -0
- package/dist/src/account/funding/consolidate.js +137 -0
- package/dist/src/{user → account/funding}/credit.d.ts +10 -10
- package/dist/src/{user → account/funding}/credit.js +6 -6
- package/dist/src/{user → account/funding}/custody.d.ts +4 -4
- package/dist/src/{user → account/funding}/custody.js +2 -2
- package/dist/src/{utils → account/funding}/wormhole.d.ts +4 -4
- package/dist/src/{utils → account/funding}/wormhole.js +1 -1
- package/dist/src/account/index.d.ts +29 -0
- package/dist/src/account/index.js +29 -0
- package/dist/src/{user → account}/referral.d.ts +3 -3
- package/dist/src/{user → account}/referral.js +1 -1
- package/dist/src/base-client.d.ts +74 -0
- package/dist/src/base-client.js +97 -0
- package/dist/src/constants.d.ts +4 -46
- package/dist/src/constants.js +8 -52
- package/dist/src/generated/bucket_v2_framework/liability.d.ts +0 -26
- package/dist/src/generated/bucket_v2_framework/liability.js +0 -28
- package/dist/src/generated/waterx_account/account.d.ts +50 -15
- package/dist/src/generated/waterx_account/account.js +51 -15
- package/dist/src/generated/waterx_oracle/oracle.d.ts +7 -1
- package/dist/src/generated/waterx_oracle/oracle.js +7 -2
- package/dist/src/{prediction/generated → generated}/waterx_prediction/account_data.d.ts +19 -2
- package/dist/src/{prediction/generated → generated}/waterx_prediction/admin.d.ts +3 -1
- package/dist/src/{prediction/generated → generated}/waterx_prediction/deps/sui/balance.d.ts +3 -1
- package/dist/src/{prediction/generated/waterx_account → generated/waterx_prediction}/deps/sui/table.d.ts +6 -1
- package/dist/src/generated/waterx_prediction/events.d.ts +288 -0
- package/dist/src/{prediction/generated → generated}/waterx_prediction/events.js +39 -0
- package/dist/src/{prediction/generated → generated}/waterx_prediction/global_config.d.ts +6 -1
- package/dist/src/{prediction/generated → generated}/waterx_prediction/order.d.ts +34 -1
- package/dist/src/{prediction/generated → generated}/waterx_prediction/position.d.ts +16 -1
- package/dist/src/{prediction/generated → generated}/waterx_prediction/view.d.ts +69 -4
- package/dist/src/{prediction/generated → generated}/waterx_prediction/waterx_prediction.d.ts +162 -2
- package/dist/src/{prediction/generated → generated}/waterx_prediction/waterx_prediction.js +99 -0
- package/dist/src/generated/waterx_pyth_rule/pyth_rule.d.ts +102 -0
- package/dist/src/generated/waterx_pyth_rule/pyth_rule.js +99 -0
- package/dist/src/generated/waterx_supra_rule/supra_rule.d.ts +5 -5
- package/dist/src/generated/waterx_supra_rule/supra_rule.js +1 -2
- package/dist/src/generated/withdrawal_queue/withdrawal_queue.d.ts +23 -23
- package/dist/src/generated/withdrawal_queue/withdrawal_queue.js +3 -6
- package/dist/src/oracle/aggregate.d.ts +74 -0
- package/dist/src/oracle/aggregate.js +112 -0
- package/dist/src/oracle/config.d.ts +99 -0
- package/dist/src/oracle/config.js +23 -0
- package/dist/src/oracle/host.d.ts +32 -0
- package/dist/src/oracle/host.js +10 -0
- package/dist/src/oracle/index.d.ts +16 -0
- package/dist/src/oracle/index.js +18 -0
- package/dist/src/oracle/pyth.d.ts +52 -0
- package/dist/src/oracle/pyth.js +220 -0
- package/dist/src/oracle/rules/constant-rule.d.ts +9 -0
- package/dist/src/oracle/rules/constant-rule.js +14 -0
- package/dist/src/oracle/rules/pyth-rule.d.ts +11 -0
- package/dist/src/oracle/rules/pyth-rule.js +20 -0
- package/dist/src/oracle/rules/sponsor.d.ts +28 -0
- package/dist/src/oracle/rules/sponsor.js +48 -0
- package/dist/src/oracle/rules/supra-rule.d.ts +11 -0
- package/dist/src/oracle/rules/supra-rule.js +22 -0
- package/dist/src/perp/client.d.ts +78 -0
- package/dist/src/perp/client.js +108 -0
- package/dist/src/{client.d.ts → perp/config-view.d.ts} +15 -60
- package/dist/src/{client.js → perp/config-view.js} +23 -95
- package/dist/src/perp/config.d.ts +126 -0
- package/dist/src/{config.js → perp/config.js} +11 -12
- package/dist/src/perp/constants.d.ts +49 -0
- package/dist/src/perp/constants.js +61 -0
- package/dist/src/perp/fetch/account.d.ts +43 -0
- package/dist/src/perp/fetch/account.js +64 -0
- package/dist/src/perp/fetch/bridge.d.ts +90 -0
- package/dist/src/perp/fetch/bridge.js +127 -0
- package/dist/src/perp/fetch/custody.d.ts +32 -0
- package/dist/src/perp/fetch/custody.js +62 -0
- package/dist/src/perp/fetch/market.d.ts +30 -0
- package/dist/src/perp/fetch/market.js +68 -0
- package/dist/src/perp/fetch/positions.d.ts +70 -0
- package/dist/src/perp/fetch/positions.js +185 -0
- package/dist/src/perp/fetch/simulate.d.ts +12 -0
- package/dist/src/perp/fetch/simulate.js +13 -0
- package/dist/src/perp/fetch.d.ts +23 -0
- package/dist/src/perp/fetch.js +23 -0
- package/dist/src/{index.d.ts → perp/index.d.ts} +21 -21
- package/dist/src/{index.js → perp/index.js} +21 -21
- package/dist/src/perp/tx-builders/common.d.ts +83 -0
- package/dist/src/perp/tx-builders/common.js +70 -0
- package/dist/src/perp/tx-builders/credit.d.ts +65 -0
- package/dist/src/perp/tx-builders/credit.js +62 -0
- package/dist/src/perp/tx-builders/rewards.d.ts +30 -0
- package/dist/src/perp/tx-builders/rewards.js +34 -0
- package/dist/src/perp/tx-builders/trading.d.ts +51 -0
- package/dist/src/perp/tx-builders/trading.js +59 -0
- package/dist/src/perp/tx-builders/wlp.d.ts +90 -0
- package/dist/src/perp/tx-builders/wlp.js +120 -0
- package/dist/src/perp/tx-builders.d.ts +23 -0
- package/dist/src/perp/tx-builders.js +23 -0
- package/dist/src/perp/user/index.d.ts +8 -0
- package/dist/src/perp/user/index.js +8 -0
- package/dist/src/{user → perp/user}/order.d.ts +7 -7
- package/dist/src/{user → perp/user}/order.js +3 -3
- package/dist/src/{user → perp/user}/staking.d.ts +4 -4
- package/dist/src/{user → perp/user}/staking.js +2 -2
- package/dist/src/{user → perp/user}/trading.d.ts +13 -13
- package/dist/src/{user → perp/user}/trading.js +2 -2
- package/dist/src/{user → perp/user}/wlp.d.ts +7 -7
- package/dist/src/{user → perp/user}/wlp.js +3 -3
- package/dist/src/prediction/account.js +40 -76
- package/dist/src/prediction/client.d.ts +8 -38
- package/dist/src/prediction/client.js +11 -67
- package/dist/src/prediction/config.d.ts +16 -2
- package/dist/src/prediction/config.js +10 -4
- package/dist/src/prediction/index.d.ts +11 -11
- package/dist/src/prediction/index.js +10 -10
- package/dist/src/prediction/prediction.d.ts +45 -0
- package/dist/src/prediction/prediction.js +71 -0
- package/dist/src/prediction/tx-builders.d.ts +4 -4
- package/dist/src/prediction/tx-builders.js +2 -2
- package/dist/src/prediction/user/index.d.ts +2 -2
- package/dist/src/prediction/user/index.js +1 -1
- package/dist/src/prediction/user/position.d.ts +2 -2
- package/dist/src/prediction/user/position.js +1 -1
- package/dist/src/prediction/utils/bcs.d.ts +5 -0
- package/dist/src/prediction/utils/bcs.js +5 -0
- package/dist/src/prediction/utils/index.d.ts +7 -0
- package/dist/src/prediction/utils/index.js +7 -0
- package/dist/src/sdk.d.ts +10 -6
- package/dist/src/sdk.js +9 -5
- package/dist/src/unified-client.d.ts +140 -145
- package/dist/src/unified-client.js +98 -40
- package/dist/src/utils/config.d.ts +1 -1
- package/package.json +22 -5
- package/dist/src/config.d.ts +0 -292
- package/dist/src/fetch.d.ts +0 -254
- package/dist/src/fetch.js +0 -564
- package/dist/src/prediction/generated/bucket_v2_framework/account.d.ts +0 -100
- package/dist/src/prediction/generated/bucket_v2_framework/account.js +0 -129
- package/dist/src/prediction/generated/bucket_v2_framework/deps/std/type_name.d.ts +0 -6
- package/dist/src/prediction/generated/bucket_v2_framework/deps/std/type_name.js +0 -19
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/balance.d.ts +0 -10
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_map.d.ts +0 -36
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_map.js +0 -27
- package/dist/src/prediction/generated/bucket_v2_framework/double.d.ts +0 -382
- package/dist/src/prediction/generated/bucket_v2_framework/double.js +0 -466
- package/dist/src/prediction/generated/bucket_v2_framework/float.d.ts +0 -362
- package/dist/src/prediction/generated/bucket_v2_framework/float.js +0 -440
- package/dist/src/prediction/generated/bucket_v2_framework/liability.d.ts +0 -193
- package/dist/src/prediction/generated/bucket_v2_framework/liability.js +0 -205
- package/dist/src/prediction/generated/bucket_v2_framework/linked_table.d.ts +0 -384
- package/dist/src/prediction/generated/bucket_v2_framework/linked_table.js +0 -382
- package/dist/src/prediction/generated/bucket_v2_framework/sheet.d.ts +0 -344
- package/dist/src/prediction/generated/bucket_v2_framework/sheet.js +0 -338
- package/dist/src/prediction/generated/utils/index.d.ts +0 -30
- package/dist/src/prediction/generated/utils/index.js +0 -160
- package/dist/src/prediction/generated/waterx_account/account.d.ts +0 -1589
- package/dist/src/prediction/generated/waterx_account/account.js +0 -1758
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/liability.d.ts +0 -7
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/liability.js +0 -13
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/sheet.d.ts +0 -7
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/sheet.js +0 -16
- package/dist/src/prediction/generated/waterx_account/deps/std/type_name.d.ts +0 -6
- package/dist/src/prediction/generated/waterx_account/deps/std/type_name.js +0 -19
- package/dist/src/prediction/generated/waterx_account/deps/sui/balance.d.ts +0 -10
- package/dist/src/prediction/generated/waterx_account/deps/sui/balance.js +0 -14
- package/dist/src/prediction/generated/waterx_account/deps/sui/object_table.d.ts +0 -12
- package/dist/src/prediction/generated/waterx_account/deps/sui/object_table.js +0 -19
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_map.d.ts +0 -36
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_map.js +0 -27
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_set.d.ts +0 -16
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_set.js +0 -19
- package/dist/src/prediction/generated/waterx_account/direct_rule.d.ts +0 -75
- package/dist/src/prediction/generated/waterx_account/direct_rule.js +0 -78
- package/dist/src/prediction/generated/waterx_account/events.d.ts +0 -33
- package/dist/src/prediction/generated/waterx_account/events.js +0 -137
- package/dist/src/prediction/generated/waterx_account/version.js +0 -8
- package/dist/src/prediction/generated/waterx_prediction/bet_sharing.d.ts +0 -60
- package/dist/src/prediction/generated/waterx_prediction/bet_sharing.js +0 -83
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/balance.js +0 -14
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/table.d.ts +0 -24
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/table.js +0 -31
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/vec_set.d.ts +0 -16
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/vec_set.js +0 -19
- package/dist/src/prediction/generated/waterx_prediction/events.d.ts +0 -22
- package/dist/src/prediction/generated/waterx_prediction/version.d.ts +0 -10
- package/dist/src/tx-builders.d.ts +0 -296
- package/dist/src/tx-builders.js +0 -461
- package/dist/src/user/index.d.ts +0 -8
- package/dist/src/user/index.js +0 -8
- package/dist/src/utils/pyth.d.ts +0 -124
- package/dist/src/utils/pyth.js +0 -392
- /package/dist/src/{utils → account}/account-request.js +0 -0
- /package/dist/src/{core → account}/waterx-account.d.ts +0 -0
- /package/dist/src/{core → account}/waterx-account.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/account_data.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/admin.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/deps/bucket_v2_framework/linked_table.d.ts +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/deps/bucket_v2_framework/linked_table.js +0 -0
- /package/dist/src/{prediction/generated/bucket_v2_framework → generated/waterx_prediction}/deps/sui/balance.js +0 -0
- /package/dist/src/{prediction/generated/waterx_account → generated/waterx_prediction}/deps/sui/table.js +0 -0
- /package/dist/src/{prediction/generated/bucket_v2_framework → generated/waterx_prediction}/deps/sui/vec_set.d.ts +0 -0
- /package/dist/src/{prediction/generated/bucket_v2_framework → generated/waterx_prediction}/deps/sui/vec_set.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/global_config.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/order.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/outcome.d.ts +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/outcome.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/position.js +0 -0
- /package/dist/src/{prediction/generated/waterx_account → generated/waterx_prediction}/version.d.ts +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/version.js +0 -0
- /package/dist/src/{prediction/generated → generated}/waterx_prediction/view.js +0 -0
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { PerpClient } from "./client.ts";
|
|
2
2
|
export type { CreateClientOptions } from "./client.ts";
|
|
3
3
|
export { PYTH_DEFAULTS, WORMHOLE_DEFAULTS, clearConfigCache, defaultConfigUrl, loadConfig, } from "./config.ts";
|
|
4
4
|
export type { BasePackageEntry, ConstantFeedEntry, WaterxReferralPackage, LoadConfigOptions, NativeCustodyAsset, NativeCustodyPackage, PythInfraConfig, PythRulePackage, PythSponsorRulePackage, SupraFeedEntry, SupraRulePackage, TestnetFaucetPackage, TrustedEmitterRow, WaterXConfig, WaterXPackages, WaterxCreditPackage, WaterxOraclePackage, WaterxPerpMarketEntry, WaterxPerpPackage, WaterxStakingPackage, WithdrawalQueuePackage, WlpPackage, WormholeBridgePackage, WormholeInfraConfig, WxaAccountPackage, } from "./config.ts";
|
|
5
5
|
export { ACTION_ADD_PRE_ORDER, ACTION_CANCEL_ORDER, ACTION_CANCEL_PRE_ORDER, ACTION_CLOSE_POSITION, ACTION_DECREASE_POSITION, ACTION_DEPOSIT_COLLATERAL, ACTION_INCREASE_POSITION, ACTION_LIQUIDATE, ACTION_OPEN_POSITION, ACTION_PLACE_ORDER, ACTION_UPDATE_ORDER, ACTION_WITHDRAW_COLLATERAL, BPS_SCALE, CRYPTO_FEE_RATE, DOUBLE_SCALE, DRY_RUN_SENDER, FLOAT_SCALE, MAINTENANCE_MARGIN_RATE, ORDER_LIMIT_BUY, ORDER_LIMIT_SELL, ORDER_STOP_BUY, ORDER_STOP_SELL, ORDER_TAG_WILDCARD, PERM_ALL, PERM_ALL_TRADING, PERM_CANCEL_ORDER, PERM_CLOSE_POSITION, PERM_DECREASE_POSITION, PERM_DEPOSIT_COLLATERAL, PERM_INCREASE_POSITION, PERM_MINT_WLP, PERM_OPEN_POSITION, PERM_PLACE_ORDER, PERM_REDEEM_WLP, PERM_WITHDRAW_COLLATERAL, STAKING_PERM_DEPOSIT_STAKE, STAKING_PERM_REDEEM_STAKE, STAKING_PERM_CLAIM_REWARD, STAKING_PERM_ALL, STOCK_FEE_RATE, MS_PER_YEAR, SUI_DECIMALS, WLP_DECIMALS, COLLATERAL_DECIMALS, TOKEN_DECIMALS, } from "./constants.ts";
|
|
6
6
|
export type { Network } from "./constants.ts";
|
|
7
|
-
export { getMarketTickers, getCollateralAssets } from "
|
|
8
|
-
export { annualizedApyFromRatio, annualizeFundingRate, calcBorrowRate, calcBorrowRateAccrual, calcDynamicFeeBps, calcEffectiveCollateralUsd, calcEstLiqPrice, calcFee, calcFundingFeeUsd, calcFundingRate, calcImpactFeeRate, calcLeverage, calcMaxReducibleCollateralUsd, calcNotional, calcPositionBorrowFee, calcTokenUtilizationBps, calcTotalTradingFeeRate, calcUnrealizedPnl, calcWlpIncentiveApy, calcWlpMintOut, calcWlpPrice, calcWlpRedeemOut, decodeFundingIndexDelta, rawPrice, } from "
|
|
7
|
+
export { getMarketTickers, getCollateralAssets } from "../utils/config.ts";
|
|
8
|
+
export { annualizedApyFromRatio, annualizeFundingRate, calcBorrowRate, calcBorrowRateAccrual, calcDynamicFeeBps, calcEffectiveCollateralUsd, calcEstLiqPrice, calcFee, calcFundingFeeUsd, calcFundingRate, calcImpactFeeRate, calcLeverage, calcMaxReducibleCollateralUsd, calcNotional, calcPositionBorrowFee, calcTokenUtilizationBps, calcTotalTradingFeeRate, calcUnrealizedPnl, calcWlpIncentiveApy, calcWlpMintOut, calcWlpPrice, calcWlpRedeemOut, decodeFundingIndexDelta, rawPrice, } from "../utils/math.ts";
|
|
9
9
|
export * from "./user/index.ts";
|
|
10
10
|
export * from "./tx-builders.ts";
|
|
11
11
|
export * from "./fetch.ts";
|
|
12
|
-
export { PythCache, aggregateTicker, aggregateTickerWithConstant, aggregateTickerWithPyth, buildPythPriceUpdateCalls, fetchPriceFeedsUpdateData, refreshOraclePrices, updatePythPrices, } from "
|
|
13
|
-
export { fetchDepositVaa, fetchVaa, listBridgeWithdrawalVaas, listVaasByEmitter, padEvmEmitter, toWormholescanEmitter, vaaBase64ToBytes, vaaBase64ToHex, vaaBytesToBase64, waitForVaa, } from "
|
|
14
|
-
export type { VaaListItem, VaaResponse, WormholescanOptions } from "
|
|
15
|
-
export { AccountData as AccountDataBcs, GlobalConfigData as GlobalConfigDataBcs, MarketData as MarketDataBcs, OrderData as OrderDataBcs, PoolData as PoolDataBcs, PositionData as PositionDataBcs, RedeemRequestData as RedeemRequestDataBcs, TokenPoolData as TokenPoolDataBcs, } from "
|
|
16
|
-
export { Position as PositionBcs, Order as OrderBcs } from "
|
|
17
|
-
export { Market as MarketBcs } from "
|
|
18
|
-
export { MarketConfig as MarketConfigBcs } from "
|
|
19
|
-
export * as tradingCalls from "
|
|
20
|
-
export * as lpPoolCalls from "
|
|
21
|
-
export * as viewCalls from "
|
|
22
|
-
export * as wxaAccountCalls from "
|
|
23
|
-
export * as stakingCalls from "
|
|
24
|
-
export * as oracleCalls from "
|
|
25
|
-
export * as pythRuleCalls from "
|
|
26
|
-
export * as pythSponsorRuleCalls from "
|
|
27
|
-
export * as referralCalls from "
|
|
28
|
-
export * as nativeCustodyCalls from "
|
|
29
|
-
export * as withdrawalQueueCalls from "
|
|
12
|
+
export { PythCache, aggregateTicker, aggregateTickerWithConstant, aggregateTickerWithPyth, buildPythPriceUpdateCalls, fetchPriceFeedsUpdateData, refreshOraclePrices, updatePythPrices, } from "../oracle/index.ts";
|
|
13
|
+
export { fetchDepositVaa, fetchVaa, listBridgeWithdrawalVaas, listVaasByEmitter, padEvmEmitter, toWormholescanEmitter, vaaBase64ToBytes, vaaBase64ToHex, vaaBytesToBase64, waitForVaa, } from "../account/funding/wormhole.ts";
|
|
14
|
+
export type { VaaListItem, VaaResponse, WormholescanOptions } from "../account/funding/wormhole.ts";
|
|
15
|
+
export { AccountData as AccountDataBcs, GlobalConfigData as GlobalConfigDataBcs, MarketData as MarketDataBcs, OrderData as OrderDataBcs, PoolData as PoolDataBcs, PositionData as PositionDataBcs, RedeemRequestData as RedeemRequestDataBcs, TokenPoolData as TokenPoolDataBcs, } from "../generated/waterx_perp_view/view.ts";
|
|
16
|
+
export { Position as PositionBcs, Order as OrderBcs } from "../generated/waterx_perp/position.ts";
|
|
17
|
+
export { Market as MarketBcs } from "../generated/waterx_perp/trading.ts";
|
|
18
|
+
export { MarketConfig as MarketConfigBcs } from "../generated/waterx_perp/market_config.ts";
|
|
19
|
+
export * as tradingCalls from "../generated/waterx_perp/trading.ts";
|
|
20
|
+
export * as lpPoolCalls from "../generated/waterx_perp/lp_pool.ts";
|
|
21
|
+
export * as viewCalls from "../generated/waterx_perp_view/view.ts";
|
|
22
|
+
export * as wxaAccountCalls from "../generated/waterx_account/account.ts";
|
|
23
|
+
export * as stakingCalls from "../generated/waterx_staking/waterx_staking.ts";
|
|
24
|
+
export * as oracleCalls from "../generated/waterx_oracle/oracle.ts";
|
|
25
|
+
export * as pythRuleCalls from "../generated/waterx_pyth_rule/pyth_rule.ts";
|
|
26
|
+
export * as pythSponsorRuleCalls from "../generated/pyth_sponsor_rule/pyth_sponsor_rule.ts";
|
|
27
|
+
export * as referralCalls from "../generated/waterx_referral/referral_table.ts";
|
|
28
|
+
export * as nativeCustodyCalls from "../generated/native_custody/custody_vault.ts";
|
|
29
|
+
export * as withdrawalQueueCalls from "../generated/withdrawal_queue/withdrawal_queue.ts";
|
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
// ======== Core ========
|
|
2
|
-
export {
|
|
2
|
+
export { PerpClient } from "./client.js";
|
|
3
3
|
export { PYTH_DEFAULTS, WORMHOLE_DEFAULTS, clearConfigCache, defaultConfigUrl, loadConfig, } from "./config.js";
|
|
4
4
|
// ======== Constants & enums ========
|
|
5
5
|
export { ACTION_ADD_PRE_ORDER, ACTION_CANCEL_ORDER, ACTION_CANCEL_PRE_ORDER, ACTION_CLOSE_POSITION, ACTION_DECREASE_POSITION, ACTION_DEPOSIT_COLLATERAL, ACTION_INCREASE_POSITION, ACTION_LIQUIDATE, ACTION_OPEN_POSITION, ACTION_PLACE_ORDER, ACTION_UPDATE_ORDER, ACTION_WITHDRAW_COLLATERAL, BPS_SCALE, CRYPTO_FEE_RATE, DOUBLE_SCALE, DRY_RUN_SENDER, FLOAT_SCALE, MAINTENANCE_MARGIN_RATE, ORDER_LIMIT_BUY, ORDER_LIMIT_SELL, ORDER_STOP_BUY, ORDER_STOP_SELL, ORDER_TAG_WILDCARD, PERM_ALL, PERM_ALL_TRADING, PERM_CANCEL_ORDER, PERM_CLOSE_POSITION, PERM_DECREASE_POSITION, PERM_DEPOSIT_COLLATERAL, PERM_INCREASE_POSITION, PERM_MINT_WLP, PERM_OPEN_POSITION, PERM_PLACE_ORDER, PERM_REDEEM_WLP, PERM_WITHDRAW_COLLATERAL, STAKING_PERM_DEPOSIT_STAKE, STAKING_PERM_REDEEM_STAKE, STAKING_PERM_CLAIM_REWARD, STAKING_PERM_ALL, STOCK_FEE_RATE, MS_PER_YEAR, SUI_DECIMALS, WLP_DECIMALS, COLLATERAL_DECIMALS, TOKEN_DECIMALS, } from "./constants.js";
|
|
6
6
|
// ======== Utilities ========
|
|
7
|
-
export { getMarketTickers, getCollateralAssets } from "
|
|
8
|
-
export { annualizedApyFromRatio, annualizeFundingRate, calcBorrowRate, calcBorrowRateAccrual, calcDynamicFeeBps, calcEffectiveCollateralUsd, calcEstLiqPrice, calcFee, calcFundingFeeUsd, calcFundingRate, calcImpactFeeRate, calcLeverage, calcMaxReducibleCollateralUsd, calcNotional, calcPositionBorrowFee, calcTokenUtilizationBps, calcTotalTradingFeeRate, calcUnrealizedPnl, calcWlpIncentiveApy, calcWlpMintOut, calcWlpPrice, calcWlpRedeemOut, decodeFundingIndexDelta, rawPrice, } from "
|
|
7
|
+
export { getMarketTickers, getCollateralAssets } from "../utils/config.js";
|
|
8
|
+
export { annualizedApyFromRatio, annualizeFundingRate, calcBorrowRate, calcBorrowRateAccrual, calcDynamicFeeBps, calcEffectiveCollateralUsd, calcEstLiqPrice, calcFee, calcFundingFeeUsd, calcFundingRate, calcImpactFeeRate, calcLeverage, calcMaxReducibleCollateralUsd, calcNotional, calcPositionBorrowFee, calcTokenUtilizationBps, calcTotalTradingFeeRate, calcUnrealizedPnl, calcWlpIncentiveApy, calcWlpMintOut, calcWlpPrice, calcWlpRedeemOut, decodeFundingIndexDelta, rawPrice, } from "../utils/math.js";
|
|
9
9
|
// ======== Transaction builders (user-side) ========
|
|
10
10
|
export * from "./user/index.js";
|
|
11
11
|
// ======== High-level Tx builders ========
|
|
12
12
|
export * from "./tx-builders.js";
|
|
13
13
|
// ======== Read-only queries ========
|
|
14
14
|
export * from "./fetch.js";
|
|
15
|
-
// ======== Pyth
|
|
16
|
-
export { PythCache, aggregateTicker, aggregateTickerWithConstant, aggregateTickerWithPyth, buildPythPriceUpdateCalls, fetchPriceFeedsUpdateData, refreshOraclePrices, updatePythPrices, } from "
|
|
15
|
+
// ======== Oracle utilities (Pyth source + rule aggregation) ========
|
|
16
|
+
export { PythCache, aggregateTicker, aggregateTickerWithConstant, aggregateTickerWithPyth, buildPythPriceUpdateCalls, fetchPriceFeedsUpdateData, refreshOraclePrices, updatePythPrices, } from "../oracle/index.js";
|
|
17
17
|
// ======== Wormhole / Wormholescan utilities (credit bridge) ========
|
|
18
|
-
export { fetchDepositVaa, fetchVaa, listBridgeWithdrawalVaas, listVaasByEmitter, padEvmEmitter, toWormholescanEmitter, vaaBase64ToBytes, vaaBase64ToHex, vaaBytesToBase64, waitForVaa, } from "
|
|
18
|
+
export { fetchDepositVaa, fetchVaa, listBridgeWithdrawalVaas, listVaasByEmitter, padEvmEmitter, toWormholescanEmitter, vaaBase64ToBytes, vaaBase64ToHex, vaaBytesToBase64, waitForVaa, } from "../account/funding/wormhole.js";
|
|
19
19
|
// ======== Generated BCS types (sui-ts-codegen) ========
|
|
20
|
-
export { AccountData as AccountDataBcs, GlobalConfigData as GlobalConfigDataBcs, MarketData as MarketDataBcs, OrderData as OrderDataBcs, PoolData as PoolDataBcs, PositionData as PositionDataBcs, RedeemRequestData as RedeemRequestDataBcs, TokenPoolData as TokenPoolDataBcs, } from "
|
|
21
|
-
export { Position as PositionBcs, Order as OrderBcs } from "
|
|
22
|
-
export { Market as MarketBcs } from "
|
|
23
|
-
export { MarketConfig as MarketConfigBcs } from "
|
|
20
|
+
export { AccountData as AccountDataBcs, GlobalConfigData as GlobalConfigDataBcs, MarketData as MarketDataBcs, OrderData as OrderDataBcs, PoolData as PoolDataBcs, PositionData as PositionDataBcs, RedeemRequestData as RedeemRequestDataBcs, TokenPoolData as TokenPoolDataBcs, } from "../generated/waterx_perp_view/view.js";
|
|
21
|
+
export { Position as PositionBcs, Order as OrderBcs } from "../generated/waterx_perp/position.js";
|
|
22
|
+
export { Market as MarketBcs } from "../generated/waterx_perp/trading.js";
|
|
23
|
+
export { MarketConfig as MarketConfigBcs } from "../generated/waterx_perp/market_config.js";
|
|
24
24
|
// Re-export entire generated namespaces for power users.
|
|
25
|
-
export * as tradingCalls from "
|
|
26
|
-
export * as lpPoolCalls from "
|
|
27
|
-
export * as viewCalls from "
|
|
28
|
-
export * as wxaAccountCalls from "
|
|
29
|
-
export * as stakingCalls from "
|
|
30
|
-
export * as oracleCalls from "
|
|
31
|
-
export * as pythRuleCalls from "
|
|
32
|
-
export * as pythSponsorRuleCalls from "
|
|
33
|
-
export * as referralCalls from "
|
|
34
|
-
export * as nativeCustodyCalls from "
|
|
35
|
-
export * as withdrawalQueueCalls from "
|
|
25
|
+
export * as tradingCalls from "../generated/waterx_perp/trading.js";
|
|
26
|
+
export * as lpPoolCalls from "../generated/waterx_perp/lp_pool.js";
|
|
27
|
+
export * as viewCalls from "../generated/waterx_perp_view/view.js";
|
|
28
|
+
export * as wxaAccountCalls from "../generated/waterx_account/account.js";
|
|
29
|
+
export * as stakingCalls from "../generated/waterx_staking/waterx_staking.js";
|
|
30
|
+
export * as oracleCalls from "../generated/waterx_oracle/oracle.js";
|
|
31
|
+
export * as pythRuleCalls from "../generated/waterx_pyth_rule/pyth_rule.js";
|
|
32
|
+
export * as pythSponsorRuleCalls from "../generated/pyth_sponsor_rule/pyth_sponsor_rule.js";
|
|
33
|
+
export * as referralCalls from "../generated/waterx_referral/referral_table.js";
|
|
34
|
+
export * as nativeCustodyCalls from "../generated/native_custody/custody_vault.js";
|
|
35
|
+
export * as withdrawalQueueCalls from "../generated/withdrawal_queue/withdrawal_queue.js";
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared scaffolding for the high-level perp `build*Tx` composers:
|
|
3
|
+
* `CommonBuildOpts`, the new-or-reuse PTB helper, the WLP pool-oracle refresh,
|
|
4
|
+
* and the request+execute envelope (optional Pyth-sponsor flow + pre-sweep).
|
|
5
|
+
*/
|
|
6
|
+
import { Transaction, type TransactionArgument } from "@mysten/sui/transactions";
|
|
7
|
+
import { PythCache } from "../../oracle/index.ts";
|
|
8
|
+
import type { PerpClient } from "../client.ts";
|
|
9
|
+
export interface CommonBuildOpts {
|
|
10
|
+
/** Append to an existing PTB instead of creating a new one. */
|
|
11
|
+
tx?: Transaction;
|
|
12
|
+
/** Skip oracle refresh entirely (caller manages freshness). Default: false. */
|
|
13
|
+
skipOraclePriceRefresh?: boolean;
|
|
14
|
+
/** Share a `PythCache` across builders to avoid redundant pyth_state reads. */
|
|
15
|
+
pythCache?: PythCache;
|
|
16
|
+
/**
|
|
17
|
+
* Wire the `pyth_sponsor_rule` flow:
|
|
18
|
+
* - open a Fund via `pyth_sponsor_rule::request(sponsor)`
|
|
19
|
+
* - pay Pyth update fees from the Fund (instead of `tx.gas`)
|
|
20
|
+
* - reimburse leftover into the sponsor pool + attach
|
|
21
|
+
* `PythSponsorRule` witness to the TradingRequest so markets
|
|
22
|
+
* whose `request_checklist` contains `PythSponsorRule` accept it
|
|
23
|
+
* Default: true (matches the testnet/mainnet checklist config).
|
|
24
|
+
* Pass `false` only when the market checklist is empty.
|
|
25
|
+
*/
|
|
26
|
+
useSponsor?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Pre-sweep parked backing assets (USDC, USDsui, …) at the wxa account's
|
|
29
|
+
* address into USD credit, plus any CREDIT coins/funds at the address into
|
|
30
|
+
* the internal wxa slot — see {@link appendConsolidateForSpend}. Skips empty
|
|
31
|
+
* buckets via gRPC probes so it's safe on any account.
|
|
32
|
+
*
|
|
33
|
+
* Default: `true`. Set to `false` to skip (e.g. caller already swept,
|
|
34
|
+
* deployment lacks `native_custody`, or the gRPC reads aren't worth
|
|
35
|
+
* the latency).
|
|
36
|
+
*
|
|
37
|
+
* Each enabled call adds 2 gRPC reads per configured backing asset
|
|
38
|
+
* (`getBalance` + `listCoins`).
|
|
39
|
+
*
|
|
40
|
+
* Only honored by async builders (this is an async sweep). Sync
|
|
41
|
+
* builders never auto-prepend the sweep — for those, call
|
|
42
|
+
* {@link buildConsolidateToUsdTx} separately.
|
|
43
|
+
*/
|
|
44
|
+
consolidateToUsd?: boolean;
|
|
45
|
+
}
|
|
46
|
+
interface RequestParams {
|
|
47
|
+
ticker: string;
|
|
48
|
+
collateralType: string;
|
|
49
|
+
lpType?: string;
|
|
50
|
+
}
|
|
51
|
+
export declare function newTx(opts?: CommonBuildOpts): Transaction;
|
|
52
|
+
/**
|
|
53
|
+
* Refresh every WLP pool-token oracle (+ caller-supplied extra tickers) and
|
|
54
|
+
* bump each pool token's `last_price_refresh_timestamp` so the pool's
|
|
55
|
+
* `assert_prices_fresh` passes when the next `mint_wlp` / `request_redeem` /
|
|
56
|
+
* trading `execute` runs in the same PTB.
|
|
57
|
+
*/
|
|
58
|
+
export declare function refreshWlpPoolOracles(tx: Transaction, client: PerpClient, extraTickers: string[], opts: {
|
|
59
|
+
cache?: PythCache;
|
|
60
|
+
sponsorFund?: {
|
|
61
|
+
fund: TransactionArgument;
|
|
62
|
+
packageId: string;
|
|
63
|
+
};
|
|
64
|
+
lpType?: string;
|
|
65
|
+
}): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Build the *Request + execute envelope with optional Pyth sponsor flow:
|
|
68
|
+
*
|
|
69
|
+
* [fund = sponsor.request()]
|
|
70
|
+
* refreshOraclePrices(..., sponsorFund?)
|
|
71
|
+
* req = buildRequest()
|
|
72
|
+
* [sponsor.reimburse(fund, req)]
|
|
73
|
+
* trading::execute(req)
|
|
74
|
+
*/
|
|
75
|
+
export declare function wrapRequestAndExecute(client: PerpClient, tx: Transaction, req: RequestParams & {
|
|
76
|
+
accountId: string;
|
|
77
|
+
}, collateralTicker: string, opts: CommonBuildOpts | undefined, buildRequest: (sponsorFund?: {
|
|
78
|
+
fund: TransactionArgument;
|
|
79
|
+
packageId: string;
|
|
80
|
+
}) => TransactionArgument): Promise<void>;
|
|
81
|
+
/** Run the async sweep iff `consolidateToUsd !== false`. */
|
|
82
|
+
export declare function maybeConsolidate(client: PerpClient, tx: Transaction, accountId: string, opts: CommonBuildOpts | undefined): Promise<void>;
|
|
83
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared scaffolding for the high-level perp `build*Tx` composers:
|
|
3
|
+
* `CommonBuildOpts`, the new-or-reuse PTB helper, the WLP pool-oracle refresh,
|
|
4
|
+
* and the request+execute envelope (optional Pyth-sponsor flow + pre-sweep).
|
|
5
|
+
*/
|
|
6
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
7
|
+
import { appendConsolidateForSpend } from "../../account/funding/consolidate.js";
|
|
8
|
+
import { openPythSponsorFund, refreshOraclePrices, reimbursePythSponsor, } from "../../oracle/index.js";
|
|
9
|
+
import { getCollateralAssets } from "../../utils/config.js";
|
|
10
|
+
import { executeTrading } from "../user/trading.js";
|
|
11
|
+
import { updateTokenValue } from "../user/wlp.js";
|
|
12
|
+
export function newTx(opts) {
|
|
13
|
+
return opts?.tx ?? new Transaction();
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Refresh every WLP pool-token oracle (+ caller-supplied extra tickers) and
|
|
17
|
+
* bump each pool token's `last_price_refresh_timestamp` so the pool's
|
|
18
|
+
* `assert_prices_fresh` passes when the next `mint_wlp` / `request_redeem` /
|
|
19
|
+
* trading `execute` runs in the same PTB.
|
|
20
|
+
*/
|
|
21
|
+
export async function refreshWlpPoolOracles(tx, client, extraTickers, opts) {
|
|
22
|
+
const poolTickers = getCollateralAssets(client.config);
|
|
23
|
+
const oracleTickers = Array.from(new Set([...extraTickers, ...poolTickers]));
|
|
24
|
+
await refreshOraclePrices(tx, client, oracleTickers, {
|
|
25
|
+
cache: opts.cache,
|
|
26
|
+
sponsorFund: opts.sponsorFund,
|
|
27
|
+
});
|
|
28
|
+
for (const tokenType of Object.values(client.config.packages.wlp.pool_tokens)) {
|
|
29
|
+
updateTokenValue(client, tx, { tokenType, lpType: opts.lpType });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Build the *Request + execute envelope with optional Pyth sponsor flow:
|
|
34
|
+
*
|
|
35
|
+
* [fund = sponsor.request()]
|
|
36
|
+
* refreshOraclePrices(..., sponsorFund?)
|
|
37
|
+
* req = buildRequest()
|
|
38
|
+
* [sponsor.reimburse(fund, req)]
|
|
39
|
+
* trading::execute(req)
|
|
40
|
+
*/
|
|
41
|
+
export async function wrapRequestAndExecute(client, tx, req, collateralTicker, opts, buildRequest) {
|
|
42
|
+
await maybeConsolidate(client, tx, req.accountId, opts);
|
|
43
|
+
const useSponsor = opts?.useSponsor ?? true;
|
|
44
|
+
let sponsorFund;
|
|
45
|
+
if (useSponsor)
|
|
46
|
+
sponsorFund = openPythSponsorFund(tx, client);
|
|
47
|
+
if (!opts?.skipOraclePriceRefresh) {
|
|
48
|
+
await refreshWlpPoolOracles(tx, client, [req.ticker, collateralTicker], {
|
|
49
|
+
cache: opts?.pythCache,
|
|
50
|
+
sponsorFund,
|
|
51
|
+
lpType: req.lpType,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
const tradingReq = buildRequest(sponsorFund);
|
|
55
|
+
if (sponsorFund) {
|
|
56
|
+
reimbursePythSponsor(tx, client, sponsorFund.fund, tradingReq, req.collateralType);
|
|
57
|
+
}
|
|
58
|
+
executeTrading(client, tx, {
|
|
59
|
+
ticker: req.ticker,
|
|
60
|
+
collateralType: req.collateralType,
|
|
61
|
+
lpType: req.lpType,
|
|
62
|
+
request: tradingReq,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/** Run the async sweep iff `consolidateToUsd !== false`. */
|
|
66
|
+
export async function maybeConsolidate(client, tx, accountId, opts) {
|
|
67
|
+
if (opts?.consolidateToUsd === false)
|
|
68
|
+
return;
|
|
69
|
+
await appendConsolidateForSpend(client, tx, accountId);
|
|
70
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level cross-chain credit / bridge composers: VAA redeem (EVM → Sui mint),
|
|
3
|
+
* the user-side withdraw request (encode route + `request_withdraw` + enqueue),
|
|
4
|
+
* and the keeper-side queue drain.
|
|
5
|
+
*/
|
|
6
|
+
import { Transaction, type TransactionArgument } from "@mysten/sui/transactions";
|
|
7
|
+
import { type RedeemVaaParams, type RouteWormholeParams } from "../../account/funding/credit.ts";
|
|
8
|
+
import type { PerpClient } from "../client.ts";
|
|
9
|
+
export interface BuildRedeemVaaParams extends RedeemVaaParams {
|
|
10
|
+
/** Append to an existing PTB instead of creating a new one. */
|
|
11
|
+
tx?: Transaction;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Mint (EVM → Sui): `redeem_vaa<CREDIT>` + consume the resulting
|
|
15
|
+
* `DepositRequest<CREDIT>` via the configured wxa deposit policy, in one
|
|
16
|
+
* PTB. The recipient wxa account is encoded in the VAA payload.
|
|
17
|
+
*/
|
|
18
|
+
export declare function buildRedeemVaaTx(client: PerpClient, params: BuildRedeemVaaParams): Transaction;
|
|
19
|
+
export type CreditWithdrawRoute = ({
|
|
20
|
+
kind: "wormhole";
|
|
21
|
+
} & RouteWormholeParams) | {
|
|
22
|
+
kind: "native";
|
|
23
|
+
assetType: string;
|
|
24
|
+
};
|
|
25
|
+
export interface BuildRequestCreditWithdrawParams {
|
|
26
|
+
accountId: string;
|
|
27
|
+
amount: bigint | number;
|
|
28
|
+
/** Sui-side recipient (honored for native payouts; ignored for wormhole). */
|
|
29
|
+
recipient: string;
|
|
30
|
+
route: CreditWithdrawRoute;
|
|
31
|
+
creditType?: string;
|
|
32
|
+
bucketAccount?: string | TransactionArgument;
|
|
33
|
+
tx?: Transaction;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Withdraw (user side): encode the route, `account::request_withdraw<CREDIT>`,
|
|
37
|
+
* then `withdrawal_queue::enqueue<CREDIT>` — all in one PTB. A keeper later
|
|
38
|
+
* drains the parked entry via {@link buildExecuteWithdrawalTx}.
|
|
39
|
+
*/
|
|
40
|
+
export declare function buildRequestCreditWithdrawTx(client: PerpClient, params: BuildRequestCreditWithdrawParams): Transaction;
|
|
41
|
+
export type ExecuteWithdrawalRoute = {
|
|
42
|
+
kind: "wormhole";
|
|
43
|
+
/**
|
|
44
|
+
* `Coin<SUI>` paying the Wormhole message fee. Omit to mint a zero-value
|
|
45
|
+
* coin via `0x2::coin::zero<SUI>` — sponsor-safe (never touches `tx.gas`,
|
|
46
|
+
* so Shinami-style gas stations don't reject the PTB) and free as long as
|
|
47
|
+
* `WormholeState.message_fee == 0`. Pass an explicit coin (e.g.
|
|
48
|
+
* `tx.object(...)`) once Wormhole raises the message fee.
|
|
49
|
+
*/
|
|
50
|
+
wormholeFeeCoin?: TransactionArgument;
|
|
51
|
+
} | {
|
|
52
|
+
kind: "native";
|
|
53
|
+
assetType: string;
|
|
54
|
+
};
|
|
55
|
+
export interface BuildExecuteWithdrawalParams {
|
|
56
|
+
/** Queue entry key (from the `Enqueued` event). */
|
|
57
|
+
key: bigint | number;
|
|
58
|
+
route: ExecuteWithdrawalRoute;
|
|
59
|
+
creditType?: string;
|
|
60
|
+
/** Executor identity (must be on the queue allowlist). Defaults to tx sender. */
|
|
61
|
+
bucketAccount?: string | TransactionArgument;
|
|
62
|
+
tx?: Transaction;
|
|
63
|
+
}
|
|
64
|
+
/** Keeper: drain one parked queue entry. */
|
|
65
|
+
export declare function buildExecuteWithdrawalTx(client: PerpClient, params: BuildExecuteWithdrawalParams): Transaction;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level cross-chain credit / bridge composers: VAA redeem (EVM → Sui mint),
|
|
3
|
+
* the user-side withdraw request (encode route + `request_withdraw` + enqueue),
|
|
4
|
+
* and the keeper-side queue drain.
|
|
5
|
+
*/
|
|
6
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
7
|
+
import { consumeCreditDeposit, enqueueWithdrawal, executeWithdrawalNative, executeWithdrawalWormhole, redeemVaa, requestCreditWithdraw, routeNative, routeWormhole, } from "../../account/funding/credit.js";
|
|
8
|
+
/**
|
|
9
|
+
* Mint (EVM → Sui): `redeem_vaa<CREDIT>` + consume the resulting
|
|
10
|
+
* `DepositRequest<CREDIT>` via the configured wxa deposit policy, in one
|
|
11
|
+
* PTB. The recipient wxa account is encoded in the VAA payload.
|
|
12
|
+
*/
|
|
13
|
+
export function buildRedeemVaaTx(client, params) {
|
|
14
|
+
const tx = params.tx ?? new Transaction();
|
|
15
|
+
const req = redeemVaa(client, tx, params);
|
|
16
|
+
consumeCreditDeposit(client, tx, { depositRequest: req, creditType: params.creditType });
|
|
17
|
+
return tx;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Withdraw (user side): encode the route, `account::request_withdraw<CREDIT>`,
|
|
21
|
+
* then `withdrawal_queue::enqueue<CREDIT>` — all in one PTB. A keeper later
|
|
22
|
+
* drains the parked entry via {@link buildExecuteWithdrawalTx}.
|
|
23
|
+
*/
|
|
24
|
+
export function buildRequestCreditWithdrawTx(client, params) {
|
|
25
|
+
const tx = params.tx ?? new Transaction();
|
|
26
|
+
const route = params.route.kind === "wormhole"
|
|
27
|
+
? routeWormhole(client, tx, params.route)
|
|
28
|
+
: routeNative(client, tx, { assetType: params.route.assetType });
|
|
29
|
+
const wreq = requestCreditWithdraw(client, tx, {
|
|
30
|
+
accountId: params.accountId,
|
|
31
|
+
amount: params.amount,
|
|
32
|
+
recipient: params.recipient,
|
|
33
|
+
route,
|
|
34
|
+
creditType: params.creditType,
|
|
35
|
+
bucketAccount: params.bucketAccount,
|
|
36
|
+
});
|
|
37
|
+
enqueueWithdrawal(client, tx, { withdrawRequest: wreq, creditType: params.creditType });
|
|
38
|
+
return tx;
|
|
39
|
+
}
|
|
40
|
+
/** Keeper: drain one parked queue entry. */
|
|
41
|
+
export function buildExecuteWithdrawalTx(client, params) {
|
|
42
|
+
const tx = params.tx ?? new Transaction();
|
|
43
|
+
if (params.route.kind === "wormhole") {
|
|
44
|
+
const fee = params.route.wormholeFeeCoin ??
|
|
45
|
+
tx.moveCall({ target: "0x2::coin::zero", typeArguments: ["0x2::sui::SUI"] });
|
|
46
|
+
executeWithdrawalWormhole(client, tx, {
|
|
47
|
+
key: params.key,
|
|
48
|
+
wormholeFee: fee,
|
|
49
|
+
creditType: params.creditType,
|
|
50
|
+
bucketAccount: params.bucketAccount,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
executeWithdrawalNative(client, tx, {
|
|
55
|
+
key: params.key,
|
|
56
|
+
assetType: params.route.assetType,
|
|
57
|
+
creditType: params.creditType,
|
|
58
|
+
bucketAccount: params.bucketAccount,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return tx;
|
|
62
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level reward composer: claim every accrued staking reward to the wxa
|
|
3
|
+
* account (TTO). The account owner collects each coin via `wxa_account::receive`
|
|
4
|
+
* in a separate user action.
|
|
5
|
+
*/
|
|
6
|
+
import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
|
|
7
|
+
import type { PerpClient } from "../client.ts";
|
|
8
|
+
import { type CommonBuildOpts } from "./common.ts";
|
|
9
|
+
export interface BuildClaimRewardsToAccountParams extends CommonBuildOpts {
|
|
10
|
+
accountId: string;
|
|
11
|
+
/** Staking pool alias. Defaults to `"WLP"`. */
|
|
12
|
+
stakeAlias?: string;
|
|
13
|
+
/** Fully-qualified stake coin type. Defaults to `client.wlpType()`. */
|
|
14
|
+
stakeType?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Reward coin types to claim. Defaults to every rewarder configured for the
|
|
17
|
+
* stake pool in `waterx_staking.rewarders[stakeAlias]`.
|
|
18
|
+
*/
|
|
19
|
+
rewarderTypes?: string[];
|
|
20
|
+
bucketAccount?: string | TransactionArgument;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Claims every accrued reward for `accountId` on the given stake pool. Each
|
|
24
|
+
* resulting `Coin<R>` is TTO'd to the wxa account's UID address via
|
|
25
|
+
* `wxa_account::transfer_coin<R>` (the default behaviour of the Move
|
|
26
|
+
* `staking::claim` entry — no deposit-policy registration required for the
|
|
27
|
+
* reward token). The account owner collects each coin via
|
|
28
|
+
* `wxa_account::receive` in a separate user action.
|
|
29
|
+
*/
|
|
30
|
+
export declare function buildClaimRewardsToAccountTx(client: PerpClient, params: BuildClaimRewardsToAccountParams): Transaction;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level reward composer: claim every accrued staking reward to the wxa
|
|
3
|
+
* account (TTO). The account owner collects each coin via `wxa_account::receive`
|
|
4
|
+
* in a separate user action.
|
|
5
|
+
*/
|
|
6
|
+
import { claimReward } from "../user/staking.js";
|
|
7
|
+
import { newTx } from "./common.js";
|
|
8
|
+
/**
|
|
9
|
+
* Claims every accrued reward for `accountId` on the given stake pool. Each
|
|
10
|
+
* resulting `Coin<R>` is TTO'd to the wxa account's UID address via
|
|
11
|
+
* `wxa_account::transfer_coin<R>` (the default behaviour of the Move
|
|
12
|
+
* `staking::claim` entry — no deposit-policy registration required for the
|
|
13
|
+
* reward token). The account owner collects each coin via
|
|
14
|
+
* `wxa_account::receive` in a separate user action.
|
|
15
|
+
*/
|
|
16
|
+
export function buildClaimRewardsToAccountTx(client, params) {
|
|
17
|
+
const tx = newTx(params);
|
|
18
|
+
const stakeAlias = params.stakeAlias ?? "WLP";
|
|
19
|
+
const stakeType = params.stakeType ?? client.wlpType();
|
|
20
|
+
const rewarderTypes = params.rewarderTypes ?? client.getRewarderTypes(stakeAlias);
|
|
21
|
+
if (rewarderTypes.length === 0) {
|
|
22
|
+
throw new Error(`buildClaimRewardsToAccountTx: no rewarders configured for stakeAlias=${stakeAlias}`);
|
|
23
|
+
}
|
|
24
|
+
for (const rewardType of rewarderTypes) {
|
|
25
|
+
claimReward(client, tx, {
|
|
26
|
+
accountId: params.accountId,
|
|
27
|
+
stakeAlias,
|
|
28
|
+
stakeType,
|
|
29
|
+
rewardType,
|
|
30
|
+
bucketAccount: params.bucketAccount,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return tx;
|
|
34
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level trading composers: position lifecycle (close / increase /
|
|
3
|
+
* decrease), collateral deposit / withdraw, and order lifecycle (place /
|
|
4
|
+
* cancel / update / pre-order). Each wraps the matching `*_request` builder in
|
|
5
|
+
* the shared request+execute envelope.
|
|
6
|
+
*/
|
|
7
|
+
import type { Transaction } from "@mysten/sui/transactions";
|
|
8
|
+
import type { PerpClient } from "../client.ts";
|
|
9
|
+
import { type AddPreOrderRequestParams, type CancelOrderRequestParams, type CancelPreOrderRequestParams, type PlaceOrderRequestParams, type UpdateOrderRequestParams } from "../user/order.ts";
|
|
10
|
+
import { type ClosePositionRequestParams, type DecreasePositionRequestParams, type DepositCollateralRequestParams, type IncreasePositionRequestParams, type WithdrawCollateralRequestParams } from "../user/trading.ts";
|
|
11
|
+
import { type CommonBuildOpts } from "./common.ts";
|
|
12
|
+
export interface BuildClosePositionParams extends ClosePositionRequestParams, CommonBuildOpts {
|
|
13
|
+
collateralTicker?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function buildClosePositionTx(client: PerpClient, params: BuildClosePositionParams): Promise<Transaction>;
|
|
16
|
+
export interface BuildIncreasePositionParams extends IncreasePositionRequestParams, CommonBuildOpts {
|
|
17
|
+
collateralTicker?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function buildIncreasePositionTx(client: PerpClient, params: BuildIncreasePositionParams): Promise<Transaction>;
|
|
20
|
+
export interface BuildDecreasePositionParams extends DecreasePositionRequestParams, CommonBuildOpts {
|
|
21
|
+
collateralTicker?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function buildDecreasePositionTx(client: PerpClient, params: BuildDecreasePositionParams): Promise<Transaction>;
|
|
24
|
+
export interface BuildDepositCollateralParams extends DepositCollateralRequestParams, CommonBuildOpts {
|
|
25
|
+
collateralTicker?: string;
|
|
26
|
+
}
|
|
27
|
+
export declare function buildDepositCollateralTx(client: PerpClient, params: BuildDepositCollateralParams): Promise<Transaction>;
|
|
28
|
+
export interface BuildWithdrawCollateralParams extends WithdrawCollateralRequestParams, CommonBuildOpts {
|
|
29
|
+
collateralTicker?: string;
|
|
30
|
+
}
|
|
31
|
+
export declare function buildWithdrawCollateralTx(client: PerpClient, params: BuildWithdrawCollateralParams): Promise<Transaction>;
|
|
32
|
+
export interface BuildPlaceOrderParams extends PlaceOrderRequestParams, CommonBuildOpts {
|
|
33
|
+
collateralTicker?: string;
|
|
34
|
+
}
|
|
35
|
+
export declare function buildPlaceOrderTx(client: PerpClient, params: BuildPlaceOrderParams): Promise<Transaction>;
|
|
36
|
+
export interface BuildCancelOrderParams extends CancelOrderRequestParams, CommonBuildOpts {
|
|
37
|
+
collateralTicker?: string;
|
|
38
|
+
}
|
|
39
|
+
export declare function buildCancelOrderTx(client: PerpClient, params: BuildCancelOrderParams): Promise<Transaction>;
|
|
40
|
+
export interface BuildUpdateOrderParams extends UpdateOrderRequestParams, CommonBuildOpts {
|
|
41
|
+
collateralTicker?: string;
|
|
42
|
+
}
|
|
43
|
+
export declare function buildUpdateOrderTx(client: PerpClient, params: BuildUpdateOrderParams): Promise<Transaction>;
|
|
44
|
+
export interface BuildCancelPreOrderParams extends CancelPreOrderRequestParams, CommonBuildOpts {
|
|
45
|
+
collateralTicker?: string;
|
|
46
|
+
}
|
|
47
|
+
export declare function buildCancelPreOrderTx(client: PerpClient, params: BuildCancelPreOrderParams): Promise<Transaction>;
|
|
48
|
+
export interface BuildAddPreOrderParams extends AddPreOrderRequestParams, CommonBuildOpts {
|
|
49
|
+
collateralTicker?: string;
|
|
50
|
+
}
|
|
51
|
+
export declare function buildAddPreOrderTx(client: PerpClient, params: BuildAddPreOrderParams): Promise<Transaction>;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* High-level trading composers: position lifecycle (close / increase /
|
|
3
|
+
* decrease), collateral deposit / withdraw, and order lifecycle (place /
|
|
4
|
+
* cancel / update / pre-order). Each wraps the matching `*_request` builder in
|
|
5
|
+
* the shared request+execute envelope.
|
|
6
|
+
*/
|
|
7
|
+
import { addPreOrderRequest, cancelOrderRequest, cancelPreOrderRequest, placeOrderRequest, updateOrderRequest, } from "../user/order.js";
|
|
8
|
+
import { closePositionRequest, decreasePositionRequest, depositCollateralRequest, increasePositionRequest, withdrawCollateralRequest, } from "../user/trading.js";
|
|
9
|
+
import { newTx, wrapRequestAndExecute } from "./common.js";
|
|
10
|
+
export async function buildClosePositionTx(client, params) {
|
|
11
|
+
const tx = newTx(params);
|
|
12
|
+
await wrapRequestAndExecute(client, tx, params, params.collateralTicker ?? "USDCUSD", params, () => closePositionRequest(client, tx, params));
|
|
13
|
+
return tx;
|
|
14
|
+
}
|
|
15
|
+
export async function buildIncreasePositionTx(client, params) {
|
|
16
|
+
const tx = newTx(params);
|
|
17
|
+
await wrapRequestAndExecute(client, tx, params, params.collateralTicker ?? "USDCUSD", params, () => increasePositionRequest(client, tx, params));
|
|
18
|
+
return tx;
|
|
19
|
+
}
|
|
20
|
+
export async function buildDecreasePositionTx(client, params) {
|
|
21
|
+
const tx = newTx(params);
|
|
22
|
+
await wrapRequestAndExecute(client, tx, params, params.collateralTicker ?? "USDCUSD", params, () => decreasePositionRequest(client, tx, params));
|
|
23
|
+
return tx;
|
|
24
|
+
}
|
|
25
|
+
export async function buildDepositCollateralTx(client, params) {
|
|
26
|
+
const tx = newTx(params);
|
|
27
|
+
await wrapRequestAndExecute(client, tx, params, params.collateralTicker ?? "USDCUSD", params, () => depositCollateralRequest(client, tx, params));
|
|
28
|
+
return tx;
|
|
29
|
+
}
|
|
30
|
+
export async function buildWithdrawCollateralTx(client, params) {
|
|
31
|
+
const tx = newTx(params);
|
|
32
|
+
await wrapRequestAndExecute(client, tx, params, params.collateralTicker ?? "USDCUSD", params, () => withdrawCollateralRequest(client, tx, params));
|
|
33
|
+
return tx;
|
|
34
|
+
}
|
|
35
|
+
export async function buildPlaceOrderTx(client, params) {
|
|
36
|
+
const tx = newTx(params);
|
|
37
|
+
await wrapRequestAndExecute(client, tx, params, params.collateralTicker ?? "USDCUSD", params, () => placeOrderRequest(client, tx, params));
|
|
38
|
+
return tx;
|
|
39
|
+
}
|
|
40
|
+
export async function buildCancelOrderTx(client, params) {
|
|
41
|
+
const tx = newTx(params);
|
|
42
|
+
await wrapRequestAndExecute(client, tx, params, params.collateralTicker ?? "USDCUSD", params, () => cancelOrderRequest(client, tx, params));
|
|
43
|
+
return tx;
|
|
44
|
+
}
|
|
45
|
+
export async function buildUpdateOrderTx(client, params) {
|
|
46
|
+
const tx = newTx(params);
|
|
47
|
+
await wrapRequestAndExecute(client, tx, params, params.collateralTicker ?? "USDCUSD", params, () => updateOrderRequest(client, tx, params));
|
|
48
|
+
return tx;
|
|
49
|
+
}
|
|
50
|
+
export async function buildCancelPreOrderTx(client, params) {
|
|
51
|
+
const tx = newTx(params);
|
|
52
|
+
await wrapRequestAndExecute(client, tx, params, params.collateralTicker ?? "USDCUSD", params, () => cancelPreOrderRequest(client, tx, params));
|
|
53
|
+
return tx;
|
|
54
|
+
}
|
|
55
|
+
export async function buildAddPreOrderTx(client, params) {
|
|
56
|
+
const tx = newTx(params);
|
|
57
|
+
await wrapRequestAndExecute(client, tx, params, params.collateralTicker ?? "USDCUSD", params, () => addPreOrderRequest(client, tx, params));
|
|
58
|
+
return tx;
|
|
59
|
+
}
|