@waterx/sdk 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -37
- package/dist/cjs/src/account/account.js +2 -1
- package/dist/cjs/src/account/config.d.ts +0 -16
- package/dist/cjs/src/account/funding/balance.d.ts +25 -2
- package/dist/cjs/src/account/funding/balance.js +36 -24
- package/dist/cjs/src/account/funding/credit.js +6 -10
- package/dist/cjs/src/constants.d.ts +15 -1
- package/dist/cjs/src/constants.js +18 -4
- package/dist/cjs/src/generated/waterx_rule/deps/bucket_v2_framework/float.d.ts +8 -0
- package/dist/cjs/src/generated/waterx_rule/deps/bucket_v2_framework/float.js +13 -0
- package/dist/cjs/src/generated/waterx_rule/deps/sui/vec_map.d.ts +36 -0
- package/dist/cjs/src/generated/waterx_rule/deps/sui/vec_map.js +31 -0
- package/dist/cjs/src/generated/waterx_rule/waterx_rule.d.ts +940 -0
- package/dist/cjs/src/generated/waterx_rule/waterx_rule.js +1092 -0
- package/dist/cjs/src/oracle/aggregate.d.ts +21 -21
- package/dist/cjs/src/oracle/aggregate.js +84 -71
- package/dist/cjs/src/oracle/config.d.ts +107 -52
- package/dist/cjs/src/oracle/config.js +15 -35
- package/dist/cjs/src/oracle/host.d.ts +13 -2
- package/dist/cjs/src/oracle/index.d.ts +4 -2
- package/dist/cjs/src/oracle/index.js +25 -6
- package/dist/cjs/src/oracle/price-update-rule.d.ts +3 -4
- package/dist/cjs/src/oracle/pyth.d.ts +68 -6
- package/dist/cjs/src/oracle/pyth.js +338 -22
- package/dist/cjs/src/oracle/rule-registry.d.ts +11 -6
- package/dist/cjs/src/oracle/rule-registry.js +13 -6
- package/dist/cjs/src/oracle/rules/pyth-core-rule.js +17 -2
- package/dist/cjs/src/oracle/rules/pyth-lazer-rule.d.ts +6 -6
- package/dist/cjs/src/oracle/rules/pyth-lazer-rule.js +25 -22
- package/dist/cjs/src/oracle/rules/pyth-rule.js +5 -0
- package/dist/cjs/src/oracle/rules/waterx-rule.d.ts +89 -0
- package/dist/cjs/src/oracle/rules/waterx-rule.js +272 -0
- package/dist/cjs/src/oracle/update-fetch.d.ts +32 -2
- package/dist/cjs/src/oracle/update-fetch.js +60 -3
- package/dist/cjs/src/perp/client.d.ts +71 -19
- package/dist/cjs/src/perp/client.js +30 -10
- package/dist/cjs/src/perp/config.d.ts +4 -7
- package/dist/cjs/src/perp/config.js +9 -12
- package/dist/cjs/src/perp/constants.d.ts +0 -6
- package/dist/cjs/src/perp/constants.js +11 -9
- package/dist/cjs/src/perp/fetch/account.js +3 -0
- package/dist/cjs/src/perp/fetch/bridge.js +2 -1
- package/dist/cjs/src/perp/fetch/market.js +2 -1
- package/dist/cjs/src/perp/fetch/positions.d.ts +16 -10
- package/dist/cjs/src/perp/fetch/positions.js +23 -20
- package/dist/cjs/src/perp/index.d.ts +8 -4
- package/dist/cjs/src/perp/index.js +12 -7
- package/dist/cjs/src/perp/liq-view.d.ts +64 -0
- package/dist/cjs/src/perp/liq-view.js +74 -0
- package/dist/cjs/src/perp/user/order.d.ts +13 -0
- package/dist/cjs/src/perp/user/order.js +30 -16
- package/dist/cjs/src/perp/user/staking.js +3 -2
- package/dist/cjs/src/perp/user/trading.js +25 -24
- package/dist/cjs/src/perp/user/wlp.js +6 -5
- package/dist/cjs/src/prediction/utils.d.ts +11 -2
- package/dist/cjs/src/prediction/utils.js +22 -22
- package/dist/cjs/src/unified-client.d.ts +49 -20
- package/dist/cjs/src/unified-client.js +4 -1
- package/dist/cjs/src/utils/format.d.ts +14 -0
- package/dist/cjs/src/utils/format.js +24 -0
- package/dist/cjs/src/utils/math.d.ts +304 -12
- package/dist/cjs/src/utils/math.js +397 -17
- package/dist/cjs/src/utils/validate.d.ts +69 -0
- package/dist/cjs/src/utils/validate.js +183 -0
- package/dist/src/account/account.js +2 -1
- package/dist/src/account/config.d.ts +0 -16
- package/dist/src/account/funding/balance.d.ts +25 -2
- package/dist/src/account/funding/balance.js +36 -24
- package/dist/src/account/funding/credit.js +6 -10
- package/dist/src/constants.d.ts +15 -1
- package/dist/src/constants.js +17 -3
- package/dist/src/generated/waterx_rule/deps/bucket_v2_framework/float.d.ts +8 -0
- package/dist/src/generated/waterx_rule/deps/bucket_v2_framework/float.js +10 -0
- package/dist/src/generated/waterx_rule/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/waterx_rule/deps/sui/vec_map.js +27 -0
- package/dist/src/generated/waterx_rule/waterx_rule.d.ts +940 -0
- package/dist/src/generated/waterx_rule/waterx_rule.js +991 -0
- package/dist/src/oracle/aggregate.d.ts +21 -21
- package/dist/src/oracle/aggregate.js +84 -71
- package/dist/src/oracle/config.d.ts +107 -52
- package/dist/src/oracle/config.js +14 -34
- package/dist/src/oracle/host.d.ts +13 -2
- package/dist/src/oracle/index.d.ts +4 -2
- package/dist/src/oracle/index.js +18 -7
- package/dist/src/oracle/price-update-rule.d.ts +3 -4
- package/dist/src/oracle/pyth.d.ts +68 -6
- package/dist/src/oracle/pyth.js +334 -22
- package/dist/src/oracle/rule-registry.d.ts +11 -6
- package/dist/src/oracle/rule-registry.js +13 -6
- package/dist/src/oracle/rules/pyth-core-rule.js +18 -3
- package/dist/src/oracle/rules/pyth-lazer-rule.d.ts +6 -6
- package/dist/src/oracle/rules/pyth-lazer-rule.js +26 -23
- package/dist/src/oracle/rules/pyth-rule.js +5 -0
- package/dist/src/oracle/rules/waterx-rule.d.ts +89 -0
- package/dist/src/oracle/rules/waterx-rule.js +266 -0
- package/dist/src/oracle/update-fetch.d.ts +32 -2
- package/dist/src/oracle/update-fetch.js +57 -3
- package/dist/src/perp/client.d.ts +71 -19
- package/dist/src/perp/client.js +31 -11
- package/dist/src/perp/config.d.ts +4 -7
- package/dist/src/perp/config.js +9 -12
- package/dist/src/perp/constants.d.ts +0 -6
- package/dist/src/perp/constants.js +10 -8
- package/dist/src/perp/fetch/account.js +3 -0
- package/dist/src/perp/fetch/bridge.js +2 -1
- package/dist/src/perp/fetch/market.js +2 -1
- package/dist/src/perp/fetch/positions.d.ts +16 -10
- package/dist/src/perp/fetch/positions.js +28 -20
- package/dist/src/perp/index.d.ts +8 -4
- package/dist/src/perp/index.js +5 -3
- package/dist/src/perp/liq-view.d.ts +64 -0
- package/dist/src/perp/liq-view.js +71 -0
- package/dist/src/perp/user/order.d.ts +13 -0
- package/dist/src/perp/user/order.js +30 -16
- package/dist/src/perp/user/staking.js +3 -2
- package/dist/src/perp/user/trading.js +25 -24
- package/dist/src/perp/user/wlp.js +6 -5
- package/dist/src/prediction/utils.d.ts +11 -2
- package/dist/src/prediction/utils.js +22 -22
- package/dist/src/unified-client.d.ts +49 -20
- package/dist/src/unified-client.js +4 -1
- package/dist/src/utils/format.d.ts +14 -0
- package/dist/src/utils/format.js +21 -0
- package/dist/src/utils/math.d.ts +304 -12
- package/dist/src/utils/math.js +394 -17
- package/dist/src/utils/validate.d.ts +69 -0
- package/dist/src/utils/validate.js +167 -0
- package/package.json +4 -1
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* list (`waterx_perp_view`).
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.parseWholeDollarU64 = void 0;
|
|
7
8
|
exports.positionExists = positionExists;
|
|
8
9
|
exports.getPosition = getPosition;
|
|
9
10
|
exports.getOrder = getOrder;
|
|
@@ -15,6 +16,8 @@ exports.getRedeemRequests = getRedeemRequests;
|
|
|
15
16
|
const bcs_1 = require("@mysten/sui/bcs");
|
|
16
17
|
const transactions_1 = require("@mysten/sui/transactions");
|
|
17
18
|
const view_ts_1 = require("../../generated/waterx_perp_view/view.js");
|
|
19
|
+
const validate_ts_1 = require("../../utils/validate.js");
|
|
20
|
+
Object.defineProperty(exports, "parseWholeDollarU64", { enumerable: true, get: function () { return validate_ts_1.parseWholeDollarU64; } });
|
|
18
21
|
const constants_ts_1 = require("../constants.js");
|
|
19
22
|
const simulate_ts_1 = require("./simulate.js");
|
|
20
23
|
async function positionExists(client, args) {
|
|
@@ -24,7 +27,7 @@ async function positionExists(client, args) {
|
|
|
24
27
|
arguments: {
|
|
25
28
|
marketRegistry: tx.object(client.config.packages.waterx_perp.market_registry_wlp),
|
|
26
29
|
ticker: args.ticker,
|
|
27
|
-
positionId: args.positionId,
|
|
30
|
+
positionId: (0, validate_ts_1.toU64)(args.positionId, "positionId"),
|
|
28
31
|
},
|
|
29
32
|
typeArguments: [(0, simulate_ts_1.withLp)(client, args.lpType)],
|
|
30
33
|
})(tx);
|
|
@@ -39,9 +42,9 @@ async function getPosition(client, args) {
|
|
|
39
42
|
marketRegistry: tx.object(client.config.packages.waterx_perp.market_registry_wlp),
|
|
40
43
|
ticker: args.ticker,
|
|
41
44
|
pool: tx.object(client.config.packages.wlp.wlp_pool),
|
|
42
|
-
basePriceUsd: args.basePriceUsd,
|
|
43
|
-
collateralPriceUsd: args.collateralPriceUsd,
|
|
44
|
-
positionId: args.positionId,
|
|
45
|
+
basePriceUsd: (0, validate_ts_1.toU64)(args.basePriceUsd, "basePriceUsd"),
|
|
46
|
+
collateralPriceUsd: (0, validate_ts_1.toU64)(args.collateralPriceUsd, "collateralPriceUsd"),
|
|
47
|
+
positionId: (0, validate_ts_1.toU64)(args.positionId, "positionId"),
|
|
45
48
|
},
|
|
46
49
|
typeArguments: [(0, simulate_ts_1.withLp)(client, args.lpType)],
|
|
47
50
|
})(tx);
|
|
@@ -54,10 +57,10 @@ async function getOrder(client, args) {
|
|
|
54
57
|
arguments: {
|
|
55
58
|
marketRegistry: tx.object(client.config.packages.waterx_perp.market_registry_wlp),
|
|
56
59
|
ticker: args.ticker,
|
|
57
|
-
basePriceUsd: args.basePriceUsd,
|
|
58
|
-
orderTypeTag: args.orderTypeTag,
|
|
59
|
-
triggerPrice: args.triggerPrice,
|
|
60
|
-
orderId: args.orderId,
|
|
60
|
+
basePriceUsd: (0, validate_ts_1.toU64)(args.basePriceUsd, "basePriceUsd"),
|
|
61
|
+
orderTypeTag: (0, validate_ts_1.toU8)(args.orderTypeTag, "orderTypeTag"),
|
|
62
|
+
triggerPrice: (0, validate_ts_1.toU128)(args.triggerPrice, "triggerPrice"),
|
|
63
|
+
orderId: (0, validate_ts_1.toU64)(args.orderId, "orderId"),
|
|
61
64
|
},
|
|
62
65
|
typeArguments: [(0, simulate_ts_1.withLp)(client, args.lpType)],
|
|
63
66
|
})(tx);
|
|
@@ -70,9 +73,9 @@ async function getMarketOrders(client, args) {
|
|
|
70
73
|
arguments: {
|
|
71
74
|
marketRegistry: tx.object(client.config.packages.waterx_perp.market_registry_wlp),
|
|
72
75
|
ticker: args.ticker,
|
|
73
|
-
basePriceUsd: args.basePriceUsd ?? 0n,
|
|
74
|
-
cursor: args.cursor ?? 0n,
|
|
75
|
-
pageSize: args.pageSize ?? 100n,
|
|
76
|
+
basePriceUsd: (0, validate_ts_1.toU64)(args.basePriceUsd ?? 0n, "basePriceUsd"),
|
|
77
|
+
cursor: (0, validate_ts_1.toU64)(args.cursor ?? 0n, "cursor"),
|
|
78
|
+
pageSize: (0, validate_ts_1.toU64)(args.pageSize ?? 100n, "pageSize"),
|
|
76
79
|
},
|
|
77
80
|
typeArguments: [(0, simulate_ts_1.withLp)(client, args.lpType)],
|
|
78
81
|
})(tx);
|
|
@@ -104,10 +107,10 @@ async function getMarketPositions(client, args) {
|
|
|
104
107
|
marketRegistry: tx.object(client.config.packages.waterx_perp.market_registry_wlp),
|
|
105
108
|
ticker: args.ticker,
|
|
106
109
|
pool: tx.object(client.config.packages.wlp.wlp_pool),
|
|
107
|
-
basePriceUsd: args.basePriceUsd,
|
|
108
|
-
collateralPriceUsd: args.collateralPriceUsd ?? 0n,
|
|
109
|
-
cursor: args.cursor ?? 0n,
|
|
110
|
-
pageSize: args.pageSize ?? 100n,
|
|
110
|
+
basePriceUsd: (0, validate_ts_1.toU64)(args.basePriceUsd, "basePriceUsd"),
|
|
111
|
+
collateralPriceUsd: (0, validate_ts_1.toU64)(args.collateralPriceUsd ?? 0n, "collateralPriceUsd"),
|
|
112
|
+
cursor: (0, validate_ts_1.toU64)(args.cursor ?? 0n, "cursor"),
|
|
113
|
+
pageSize: (0, validate_ts_1.toU64)(args.pageSize ?? 100n, "pageSize"),
|
|
111
114
|
},
|
|
112
115
|
typeArguments: [(0, simulate_ts_1.withLp)(client, args.lpType)],
|
|
113
116
|
})(tx);
|
|
@@ -140,8 +143,8 @@ async function getAccountPositions(client, args) {
|
|
|
140
143
|
ticker: args.ticker,
|
|
141
144
|
pool: tx.object(client.config.packages.wlp.wlp_pool),
|
|
142
145
|
wxaRegistry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
143
|
-
basePriceUsd: args.basePriceUsd,
|
|
144
|
-
collateralPriceUsd: args.collateralPriceUsd ?? 0n,
|
|
146
|
+
basePriceUsd: (0, validate_ts_1.toU64)(args.basePriceUsd, "basePriceUsd"),
|
|
147
|
+
collateralPriceUsd: (0, validate_ts_1.toU64)(args.collateralPriceUsd ?? 0n, "collateralPriceUsd"),
|
|
145
148
|
accountObjectAddress: args.accountObjectAddress,
|
|
146
149
|
},
|
|
147
150
|
typeArguments: [(0, simulate_ts_1.withLp)(client, args.lpType)],
|
|
@@ -155,7 +158,7 @@ async function getAccountOrders(client, args) {
|
|
|
155
158
|
arguments: {
|
|
156
159
|
marketRegistry: tx.object(client.config.packages.waterx_perp.market_registry_wlp),
|
|
157
160
|
ticker: args.ticker,
|
|
158
|
-
basePriceUsd: args.basePriceUsd ?? 0n,
|
|
161
|
+
basePriceUsd: (0, validate_ts_1.toU64)(args.basePriceUsd ?? 0n, "basePriceUsd"),
|
|
159
162
|
accountObjectAddress: args.accountObjectAddress,
|
|
160
163
|
},
|
|
161
164
|
typeArguments: [(0, simulate_ts_1.withLp)(client, args.lpType)],
|
|
@@ -168,8 +171,8 @@ async function getRedeemRequests(client, args = {}) {
|
|
|
168
171
|
package: client.config.packages.waterx_perp_view.published_at,
|
|
169
172
|
arguments: {
|
|
170
173
|
pool: tx.object(client.config.packages.wlp.wlp_pool),
|
|
171
|
-
cursor: args.cursor ?? 0n,
|
|
172
|
-
pageSize: args.pageSize ?? 100n,
|
|
174
|
+
cursor: (0, validate_ts_1.toU64)(args.cursor ?? 0n, "cursor"),
|
|
175
|
+
pageSize: (0, validate_ts_1.toU64)(args.pageSize ?? 100n, "pageSize"),
|
|
173
176
|
},
|
|
174
177
|
typeArguments: [(0, simulate_ts_1.withLp)(client, args.lpType)],
|
|
175
178
|
})(tx);
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
export { PerpClient } from "./client.ts";
|
|
2
2
|
export type { CreateClientOptions } from "./client.ts";
|
|
3
|
-
export { PYTH_DEFAULTS,
|
|
4
|
-
export type { BasePackageEntry, ConstantFeedEntry, WaterxReferralPackage, LoadConfigOptions, NativeCustodyAsset, NativeCustodyPackage,
|
|
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,
|
|
3
|
+
export { PYTH_DEFAULTS, WORMHOLE_DEFAULTS, clearConfigCache, loadConfig } from "./config.ts";
|
|
4
|
+
export type { BasePackageEntry, ConstantFeedEntry, WaterxReferralPackage, LoadConfigOptions, NativeCustodyAsset, NativeCustodyPackage, PythFetchPolicy, PythInfraConfig, PythLazerRulePackage, PythRulePackage, PythSponsorRulePackage, SupraFeedEntry, SupraRulePackage, TestnetFaucetPackage, WaterXConfig, WaterXPackages, WaterxCreditPackage, WaterxOraclePackage, WaterxPerpMarketEntry, WaterxPerpPackage, WaterxStakingPackage, WithdrawalQueuePackage, WlpPackage, WormholeBridgePackage, WormholeInfraConfig, WxaAccountPackage, } from "./config.ts";
|
|
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, DOUBLE_SCALE, DRY_RUN_SENDER, FLOAT_SCALE, 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, MS_PER_MINUTE, MS_PER_HOUR, MS_PER_YEAR, SUI_DECIMALS, WLP_DECIMALS, COLLATERAL_DECIMALS, TOKEN_DECIMALS, } from "./constants.ts";
|
|
6
6
|
export type { Network } from "./constants.ts";
|
|
7
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";
|
|
8
|
+
export { annualizedApyFromRatio, annualizeFundingRate, calcBorrowRate, calcBorrowRateAccrual, calcDynamicFeeBps, calcEffectiveCollateralUsd, calcEstLiqPrice, calcEstLiqPriceRaw, calcFee, calcFundingFeeUsd, calcFundingRate, calcImpactFeeRate, calcLeverage, calcMaxReducibleCollateralUsd, calcNotional, calcPositionBorrowFee, calcRealLiqNetCostUsd, calcTokenUtilizationBps, calcTotalTradingFeeRate, calcUnrealizedPnl, calcViewEstLiqFeesUsd, calcWlpIncentiveApy, calcWlpMintOut, calcWlpPrice, calcWlpRedeemOut, decodeFundingIndexDelta, rawPrice, } from "../utils/math.ts";
|
|
9
|
+
export type { ExactDecimalUsd, LiqFeeBundle, RawPriceInput } from "../utils/math.ts";
|
|
10
|
+
export { formatFundingInterval } from "../utils/format.ts";
|
|
11
|
+
export { calcEstLiqPriceRawFromView } from "./liq-view.ts";
|
|
12
|
+
export type { EstLiqPriceViewOpts } from "./liq-view.ts";
|
|
9
13
|
export * from "./user/index.ts";
|
|
10
14
|
export * from "./tx-builders.ts";
|
|
11
15
|
export * from "./fetch.ts";
|
|
@@ -36,15 +36,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
36
36
|
};
|
|
37
37
|
})();
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.COLLATERAL_DECIMALS = exports.WLP_DECIMALS = exports.SUI_DECIMALS = exports.MS_PER_YEAR = exports.
|
|
40
|
-
exports.
|
|
41
|
-
exports.withdrawalQueueCalls = exports.nativeCustodyCalls = exports.referralCalls = exports.pythSponsorRuleCalls = exports.pythRuleCalls = exports.oracleCalls = exports.stakingCalls = exports.wxaAccountCalls = exports.viewCalls = exports.lpPoolCalls = exports.tradingCalls = exports.MarketConfigBcs = exports.MarketBcs = exports.OrderBcs = exports.PositionBcs = exports.TokenPoolDataBcs = exports.RedeemRequestDataBcs = exports.PositionDataBcs = exports.PoolDataBcs = exports.OrderDataBcs = exports.MarketDataBcs = exports.GlobalConfigDataBcs = void 0;
|
|
39
|
+
exports.getMarketTickers = exports.TOKEN_DECIMALS = exports.COLLATERAL_DECIMALS = exports.WLP_DECIMALS = exports.SUI_DECIMALS = exports.MS_PER_YEAR = exports.MS_PER_HOUR = exports.MS_PER_MINUTE = exports.STAKING_PERM_ALL = exports.STAKING_PERM_CLAIM_REWARD = exports.STAKING_PERM_REDEEM_STAKE = exports.STAKING_PERM_DEPOSIT_STAKE = exports.PERM_WITHDRAW_COLLATERAL = exports.PERM_REDEEM_WLP = exports.PERM_PLACE_ORDER = exports.PERM_OPEN_POSITION = exports.PERM_MINT_WLP = exports.PERM_INCREASE_POSITION = exports.PERM_DEPOSIT_COLLATERAL = exports.PERM_DECREASE_POSITION = exports.PERM_CLOSE_POSITION = exports.PERM_CANCEL_ORDER = exports.PERM_ALL_TRADING = exports.PERM_ALL = exports.ORDER_TAG_WILDCARD = exports.ORDER_STOP_SELL = exports.ORDER_STOP_BUY = exports.ORDER_LIMIT_SELL = exports.ORDER_LIMIT_BUY = exports.FLOAT_SCALE = exports.DRY_RUN_SENDER = exports.DOUBLE_SCALE = exports.BPS_SCALE = exports.ACTION_WITHDRAW_COLLATERAL = exports.ACTION_UPDATE_ORDER = exports.ACTION_PLACE_ORDER = exports.ACTION_OPEN_POSITION = exports.ACTION_LIQUIDATE = exports.ACTION_INCREASE_POSITION = exports.ACTION_DEPOSIT_COLLATERAL = exports.ACTION_DECREASE_POSITION = exports.ACTION_CLOSE_POSITION = exports.ACTION_CANCEL_PRE_ORDER = exports.ACTION_CANCEL_ORDER = exports.ACTION_ADD_PRE_ORDER = exports.loadConfig = exports.clearConfigCache = exports.WORMHOLE_DEFAULTS = exports.PYTH_DEFAULTS = exports.PerpClient = void 0;
|
|
40
|
+
exports.vaaBase64ToHex = exports.vaaBase64ToBytes = exports.toWormholescanEmitter = exports.padEvmEmitter = exports.listVaasByEmitter = exports.listBridgeWithdrawalVaas = exports.fetchVaa = exports.fetchDepositVaa = exports.updatePythPrices = exports.refreshOraclePrices = exports.fetchPriceFeedsUpdateData = exports.buildPythPriceUpdateCalls = exports.aggregateTickerWithPyth = exports.aggregateTickerWithConstant = exports.aggregateTicker = exports.PythCache = exports.OracleSourceNotImplementedError = exports.OracleFeeSourceUnavailableError = exports.LazerApiKeyMissingError = exports.FetchPolicyError = exports.calcEstLiqPriceRawFromView = exports.formatFundingInterval = exports.rawPrice = exports.decodeFundingIndexDelta = exports.calcWlpRedeemOut = exports.calcWlpPrice = exports.calcWlpMintOut = exports.calcWlpIncentiveApy = exports.calcViewEstLiqFeesUsd = exports.calcUnrealizedPnl = exports.calcTotalTradingFeeRate = exports.calcTokenUtilizationBps = exports.calcRealLiqNetCostUsd = exports.calcPositionBorrowFee = exports.calcNotional = exports.calcMaxReducibleCollateralUsd = exports.calcLeverage = exports.calcImpactFeeRate = exports.calcFundingRate = exports.calcFundingFeeUsd = exports.calcFee = exports.calcEstLiqPriceRaw = exports.calcEstLiqPrice = exports.calcEffectiveCollateralUsd = exports.calcDynamicFeeBps = exports.calcBorrowRateAccrual = exports.calcBorrowRate = exports.annualizeFundingRate = exports.annualizedApyFromRatio = exports.getCollateralAssets = void 0;
|
|
41
|
+
exports.withdrawalQueueCalls = exports.nativeCustodyCalls = exports.referralCalls = exports.pythSponsorRuleCalls = exports.pythRuleCalls = exports.oracleCalls = exports.stakingCalls = exports.wxaAccountCalls = exports.viewCalls = exports.lpPoolCalls = exports.tradingCalls = exports.MarketConfigBcs = exports.MarketBcs = exports.OrderBcs = exports.PositionBcs = exports.TokenPoolDataBcs = exports.RedeemRequestDataBcs = exports.PositionDataBcs = exports.PoolDataBcs = exports.OrderDataBcs = exports.MarketDataBcs = exports.GlobalConfigDataBcs = exports.AccountDataBcs = exports.waitForVaa = exports.vaaBytesToBase64 = void 0;
|
|
42
42
|
// ======== Core ========
|
|
43
43
|
var client_ts_1 = require("./client.js");
|
|
44
44
|
Object.defineProperty(exports, "PerpClient", { enumerable: true, get: function () { return client_ts_1.PerpClient; } });
|
|
45
45
|
var config_ts_1 = require("./config.js");
|
|
46
46
|
Object.defineProperty(exports, "PYTH_DEFAULTS", { enumerable: true, get: function () { return config_ts_1.PYTH_DEFAULTS; } });
|
|
47
|
-
Object.defineProperty(exports, "PYTH_PRO_DEFAULTS", { enumerable: true, get: function () { return config_ts_1.PYTH_PRO_DEFAULTS; } });
|
|
48
47
|
Object.defineProperty(exports, "WORMHOLE_DEFAULTS", { enumerable: true, get: function () { return config_ts_1.WORMHOLE_DEFAULTS; } });
|
|
49
48
|
Object.defineProperty(exports, "clearConfigCache", { enumerable: true, get: function () { return config_ts_1.clearConfigCache; } });
|
|
50
49
|
Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return config_ts_1.loadConfig; } });
|
|
@@ -63,11 +62,9 @@ Object.defineProperty(exports, "ACTION_PLACE_ORDER", { enumerable: true, get: fu
|
|
|
63
62
|
Object.defineProperty(exports, "ACTION_UPDATE_ORDER", { enumerable: true, get: function () { return constants_ts_1.ACTION_UPDATE_ORDER; } });
|
|
64
63
|
Object.defineProperty(exports, "ACTION_WITHDRAW_COLLATERAL", { enumerable: true, get: function () { return constants_ts_1.ACTION_WITHDRAW_COLLATERAL; } });
|
|
65
64
|
Object.defineProperty(exports, "BPS_SCALE", { enumerable: true, get: function () { return constants_ts_1.BPS_SCALE; } });
|
|
66
|
-
Object.defineProperty(exports, "CRYPTO_FEE_RATE", { enumerable: true, get: function () { return constants_ts_1.CRYPTO_FEE_RATE; } });
|
|
67
65
|
Object.defineProperty(exports, "DOUBLE_SCALE", { enumerable: true, get: function () { return constants_ts_1.DOUBLE_SCALE; } });
|
|
68
66
|
Object.defineProperty(exports, "DRY_RUN_SENDER", { enumerable: true, get: function () { return constants_ts_1.DRY_RUN_SENDER; } });
|
|
69
67
|
Object.defineProperty(exports, "FLOAT_SCALE", { enumerable: true, get: function () { return constants_ts_1.FLOAT_SCALE; } });
|
|
70
|
-
Object.defineProperty(exports, "MAINTENANCE_MARGIN_RATE", { enumerable: true, get: function () { return constants_ts_1.MAINTENANCE_MARGIN_RATE; } });
|
|
71
68
|
Object.defineProperty(exports, "ORDER_LIMIT_BUY", { enumerable: true, get: function () { return constants_ts_1.ORDER_LIMIT_BUY; } });
|
|
72
69
|
Object.defineProperty(exports, "ORDER_LIMIT_SELL", { enumerable: true, get: function () { return constants_ts_1.ORDER_LIMIT_SELL; } });
|
|
73
70
|
Object.defineProperty(exports, "ORDER_STOP_BUY", { enumerable: true, get: function () { return constants_ts_1.ORDER_STOP_BUY; } });
|
|
@@ -89,7 +86,8 @@ Object.defineProperty(exports, "STAKING_PERM_DEPOSIT_STAKE", { enumerable: true,
|
|
|
89
86
|
Object.defineProperty(exports, "STAKING_PERM_REDEEM_STAKE", { enumerable: true, get: function () { return constants_ts_1.STAKING_PERM_REDEEM_STAKE; } });
|
|
90
87
|
Object.defineProperty(exports, "STAKING_PERM_CLAIM_REWARD", { enumerable: true, get: function () { return constants_ts_1.STAKING_PERM_CLAIM_REWARD; } });
|
|
91
88
|
Object.defineProperty(exports, "STAKING_PERM_ALL", { enumerable: true, get: function () { return constants_ts_1.STAKING_PERM_ALL; } });
|
|
92
|
-
Object.defineProperty(exports, "
|
|
89
|
+
Object.defineProperty(exports, "MS_PER_MINUTE", { enumerable: true, get: function () { return constants_ts_1.MS_PER_MINUTE; } });
|
|
90
|
+
Object.defineProperty(exports, "MS_PER_HOUR", { enumerable: true, get: function () { return constants_ts_1.MS_PER_HOUR; } });
|
|
93
91
|
Object.defineProperty(exports, "MS_PER_YEAR", { enumerable: true, get: function () { return constants_ts_1.MS_PER_YEAR; } });
|
|
94
92
|
Object.defineProperty(exports, "SUI_DECIMALS", { enumerable: true, get: function () { return constants_ts_1.SUI_DECIMALS; } });
|
|
95
93
|
Object.defineProperty(exports, "WLP_DECIMALS", { enumerable: true, get: function () { return constants_ts_1.WLP_DECIMALS; } });
|
|
@@ -107,6 +105,7 @@ Object.defineProperty(exports, "calcBorrowRateAccrual", { enumerable: true, get:
|
|
|
107
105
|
Object.defineProperty(exports, "calcDynamicFeeBps", { enumerable: true, get: function () { return math_ts_1.calcDynamicFeeBps; } });
|
|
108
106
|
Object.defineProperty(exports, "calcEffectiveCollateralUsd", { enumerable: true, get: function () { return math_ts_1.calcEffectiveCollateralUsd; } });
|
|
109
107
|
Object.defineProperty(exports, "calcEstLiqPrice", { enumerable: true, get: function () { return math_ts_1.calcEstLiqPrice; } });
|
|
108
|
+
Object.defineProperty(exports, "calcEstLiqPriceRaw", { enumerable: true, get: function () { return math_ts_1.calcEstLiqPriceRaw; } });
|
|
110
109
|
Object.defineProperty(exports, "calcFee", { enumerable: true, get: function () { return math_ts_1.calcFee; } });
|
|
111
110
|
Object.defineProperty(exports, "calcFundingFeeUsd", { enumerable: true, get: function () { return math_ts_1.calcFundingFeeUsd; } });
|
|
112
111
|
Object.defineProperty(exports, "calcFundingRate", { enumerable: true, get: function () { return math_ts_1.calcFundingRate; } });
|
|
@@ -115,15 +114,21 @@ Object.defineProperty(exports, "calcLeverage", { enumerable: true, get: function
|
|
|
115
114
|
Object.defineProperty(exports, "calcMaxReducibleCollateralUsd", { enumerable: true, get: function () { return math_ts_1.calcMaxReducibleCollateralUsd; } });
|
|
116
115
|
Object.defineProperty(exports, "calcNotional", { enumerable: true, get: function () { return math_ts_1.calcNotional; } });
|
|
117
116
|
Object.defineProperty(exports, "calcPositionBorrowFee", { enumerable: true, get: function () { return math_ts_1.calcPositionBorrowFee; } });
|
|
117
|
+
Object.defineProperty(exports, "calcRealLiqNetCostUsd", { enumerable: true, get: function () { return math_ts_1.calcRealLiqNetCostUsd; } });
|
|
118
118
|
Object.defineProperty(exports, "calcTokenUtilizationBps", { enumerable: true, get: function () { return math_ts_1.calcTokenUtilizationBps; } });
|
|
119
119
|
Object.defineProperty(exports, "calcTotalTradingFeeRate", { enumerable: true, get: function () { return math_ts_1.calcTotalTradingFeeRate; } });
|
|
120
120
|
Object.defineProperty(exports, "calcUnrealizedPnl", { enumerable: true, get: function () { return math_ts_1.calcUnrealizedPnl; } });
|
|
121
|
+
Object.defineProperty(exports, "calcViewEstLiqFeesUsd", { enumerable: true, get: function () { return math_ts_1.calcViewEstLiqFeesUsd; } });
|
|
121
122
|
Object.defineProperty(exports, "calcWlpIncentiveApy", { enumerable: true, get: function () { return math_ts_1.calcWlpIncentiveApy; } });
|
|
122
123
|
Object.defineProperty(exports, "calcWlpMintOut", { enumerable: true, get: function () { return math_ts_1.calcWlpMintOut; } });
|
|
123
124
|
Object.defineProperty(exports, "calcWlpPrice", { enumerable: true, get: function () { return math_ts_1.calcWlpPrice; } });
|
|
124
125
|
Object.defineProperty(exports, "calcWlpRedeemOut", { enumerable: true, get: function () { return math_ts_1.calcWlpRedeemOut; } });
|
|
125
126
|
Object.defineProperty(exports, "decodeFundingIndexDelta", { enumerable: true, get: function () { return math_ts_1.decodeFundingIndexDelta; } });
|
|
126
127
|
Object.defineProperty(exports, "rawPrice", { enumerable: true, get: function () { return math_ts_1.rawPrice; } });
|
|
128
|
+
var format_ts_1 = require("../utils/format.js");
|
|
129
|
+
Object.defineProperty(exports, "formatFundingInterval", { enumerable: true, get: function () { return format_ts_1.formatFundingInterval; } });
|
|
130
|
+
var liq_view_ts_1 = require("./liq-view.js");
|
|
131
|
+
Object.defineProperty(exports, "calcEstLiqPriceRawFromView", { enumerable: true, get: function () { return liq_view_ts_1.calcEstLiqPriceRawFromView; } });
|
|
127
132
|
// ======== Transaction builders (user-side) ========
|
|
128
133
|
__exportStar(require("./user/index.js"), exports);
|
|
129
134
|
// ======== High-level Tx builders ========
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* View→raw adapter for the canonical liquidation-price estimate.
|
|
3
|
+
*
|
|
4
|
+
* `calcEstLiqPriceRaw` (`utils/math.ts`) takes the twelve RAW on-chain values
|
|
5
|
+
* the Move view takes, so every consumer that already holds a fetched
|
|
6
|
+
* `PositionDataView` row had to hand-map nine of them 1:1 off the row (the
|
|
7
|
+
* other three are the probe prices + maintenance margin, which the row does not
|
|
8
|
+
* carry) — and hand-carry the price invariant below in prose. That mapping is
|
|
9
|
+
* the SDK's job, so it lives here.
|
|
10
|
+
*
|
|
11
|
+
* ## Why perp-side and not in `utils/math.ts`
|
|
12
|
+
*
|
|
13
|
+
* `PositionDataView` is a perp read type (`perp/fetch/positions.ts`, decoded
|
|
14
|
+
* from the `waterx_perp_view` BCS struct). `utils/` is the shared base that
|
|
15
|
+
* `perp/` imports FROM — pulling a perp view type down into `utils/math.ts`
|
|
16
|
+
* would invert that direction and couple the line-agnostic math to the perp
|
|
17
|
+
* read layer. So the pure math stays in `utils/`, and the adapter that knows
|
|
18
|
+
* the perp row shape sits here, one layer up. Kept out of
|
|
19
|
+
* `perp/fetch/positions.ts` too: that module is transport (build PTB →
|
|
20
|
+
* simulate → decode), this is a pure field mapping with no client.
|
|
21
|
+
*/
|
|
22
|
+
import type { PositionDataView } from "./fetch/positions.ts";
|
|
23
|
+
/**
|
|
24
|
+
* Probe prices the position row was READ AT — see the invariant on
|
|
25
|
+
* {@link calcEstLiqPriceRawFromView}. Whole-dollar u64, exactly as passed to
|
|
26
|
+
* the `perp/fetch` read (`WholeDollarUsdPrice`), plus the market's maintenance
|
|
27
|
+
* margin, which lives on `MarketData`, not on the position row.
|
|
28
|
+
*/
|
|
29
|
+
export type EstLiqPriceViewOpts = {
|
|
30
|
+
/** `MarketData.maintenance_margin` — raw 1e9-scaled Float value. */
|
|
31
|
+
maintenanceMarginRaw: bigint;
|
|
32
|
+
/** The SAME `basePriceUsd` passed to the read that produced `position`. */
|
|
33
|
+
basePriceUsd: bigint;
|
|
34
|
+
/** The SAME `collateralPriceUsd` passed to the read that produced `position`. */
|
|
35
|
+
collateralPriceUsd: bigint;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Estimated liquidation price from a fetched `PositionDataView` row —
|
|
39
|
+
* bit-identical to that row's `est_liq_price`.
|
|
40
|
+
*
|
|
41
|
+
* Maps the row's nine raw fields onto {@link calcEstLiqPriceRaw} (the op-for-op
|
|
42
|
+
* mirror of `view.move::calculate_est_liq_price`) and takes the remaining
|
|
43
|
+
* three — the two probe prices plus the market's maintenance margin — from
|
|
44
|
+
* `opts`. Returns the raw 1e9-scaled u128 price; `0n` = already liquidatable /
|
|
45
|
+
* zero size.
|
|
46
|
+
*
|
|
47
|
+
* ## INVARIANT — the prices must be the ones the row was READ AT
|
|
48
|
+
*
|
|
49
|
+
* `opts.basePriceUsd` / `opts.collateralPriceUsd` MUST be the same whole-dollar
|
|
50
|
+
* values you passed to the `perp/fetch` read that produced `position`
|
|
51
|
+
* (`getPosition`, `getMarketPositions`, `getAccountPositions`, …).
|
|
52
|
+
*
|
|
53
|
+
* `PositionDataView` does NOT carry the probe prices it was computed at, so
|
|
54
|
+
* NOTHING — not this adapter, not the type system — can check this for you.
|
|
55
|
+
* Feed different prices and the row's fee / notional-derived fields were
|
|
56
|
+
* computed against one price while the estimate is computed against another:
|
|
57
|
+
* the result is a plausible-looking number that silently disagrees with
|
|
58
|
+
* `position.est_liq_price`. Thread the prices through from the read call site;
|
|
59
|
+
* never re-fetch or re-guess them here.
|
|
60
|
+
*
|
|
61
|
+
* @throws RangeError via `calcEstLiqPriceRaw` when any raw value is negative or
|
|
62
|
+
* `collateral_decimal` is outside `[0, 19]`.
|
|
63
|
+
*/
|
|
64
|
+
export declare function calcEstLiqPriceRawFromView(position: PositionDataView, opts: EstLiqPriceViewOpts): bigint;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* View→raw adapter for the canonical liquidation-price estimate.
|
|
4
|
+
*
|
|
5
|
+
* `calcEstLiqPriceRaw` (`utils/math.ts`) takes the twelve RAW on-chain values
|
|
6
|
+
* the Move view takes, so every consumer that already holds a fetched
|
|
7
|
+
* `PositionDataView` row had to hand-map nine of them 1:1 off the row (the
|
|
8
|
+
* other three are the probe prices + maintenance margin, which the row does not
|
|
9
|
+
* carry) — and hand-carry the price invariant below in prose. That mapping is
|
|
10
|
+
* the SDK's job, so it lives here.
|
|
11
|
+
*
|
|
12
|
+
* ## Why perp-side and not in `utils/math.ts`
|
|
13
|
+
*
|
|
14
|
+
* `PositionDataView` is a perp read type (`perp/fetch/positions.ts`, decoded
|
|
15
|
+
* from the `waterx_perp_view` BCS struct). `utils/` is the shared base that
|
|
16
|
+
* `perp/` imports FROM — pulling a perp view type down into `utils/math.ts`
|
|
17
|
+
* would invert that direction and couple the line-agnostic math to the perp
|
|
18
|
+
* read layer. So the pure math stays in `utils/`, and the adapter that knows
|
|
19
|
+
* the perp row shape sits here, one layer up. Kept out of
|
|
20
|
+
* `perp/fetch/positions.ts` too: that module is transport (build PTB →
|
|
21
|
+
* simulate → decode), this is a pure field mapping with no client.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.calcEstLiqPriceRawFromView = calcEstLiqPriceRawFromView;
|
|
25
|
+
const math_ts_1 = require("../utils/math.js");
|
|
26
|
+
/**
|
|
27
|
+
* Estimated liquidation price from a fetched `PositionDataView` row —
|
|
28
|
+
* bit-identical to that row's `est_liq_price`.
|
|
29
|
+
*
|
|
30
|
+
* Maps the row's nine raw fields onto {@link calcEstLiqPriceRaw} (the op-for-op
|
|
31
|
+
* mirror of `view.move::calculate_est_liq_price`) and takes the remaining
|
|
32
|
+
* three — the two probe prices plus the market's maintenance margin — from
|
|
33
|
+
* `opts`. Returns the raw 1e9-scaled u128 price; `0n` = already liquidatable /
|
|
34
|
+
* zero size.
|
|
35
|
+
*
|
|
36
|
+
* ## INVARIANT — the prices must be the ones the row was READ AT
|
|
37
|
+
*
|
|
38
|
+
* `opts.basePriceUsd` / `opts.collateralPriceUsd` MUST be the same whole-dollar
|
|
39
|
+
* values you passed to the `perp/fetch` read that produced `position`
|
|
40
|
+
* (`getPosition`, `getMarketPositions`, `getAccountPositions`, …).
|
|
41
|
+
*
|
|
42
|
+
* `PositionDataView` does NOT carry the probe prices it was computed at, so
|
|
43
|
+
* NOTHING — not this adapter, not the type system — can check this for you.
|
|
44
|
+
* Feed different prices and the row's fee / notional-derived fields were
|
|
45
|
+
* computed against one price while the estimate is computed against another:
|
|
46
|
+
* the result is a plausible-looking number that silently disagrees with
|
|
47
|
+
* `position.est_liq_price`. Thread the prices through from the read call site;
|
|
48
|
+
* never re-fetch or re-guess them here.
|
|
49
|
+
*
|
|
50
|
+
* @throws RangeError via `calcEstLiqPriceRaw` when any raw value is negative or
|
|
51
|
+
* `collateral_decimal` is outside `[0, 19]`.
|
|
52
|
+
*/
|
|
53
|
+
function calcEstLiqPriceRawFromView(position, opts) {
|
|
54
|
+
return (0, math_ts_1.calcEstLiqPriceRaw)({
|
|
55
|
+
isLong: position.is_long,
|
|
56
|
+
sizeRaw: BigInt(position.size),
|
|
57
|
+
avgPriceRaw: BigInt(position.average_price),
|
|
58
|
+
collateralAmountRaw: BigInt(position.collateral_amount),
|
|
59
|
+
collateralDecimal: position.collateral_decimal,
|
|
60
|
+
basePriceUsd: opts.basePriceUsd,
|
|
61
|
+
collateralPriceUsd: opts.collateralPriceUsd,
|
|
62
|
+
maintenanceMarginRaw: opts.maintenanceMarginRaw,
|
|
63
|
+
// The view pre-combines accrued + unrealized into `borrow_fee` / `funding_fee`
|
|
64
|
+
// — take those, NOT the `unrealized_*` pair, which would UNDER-count:
|
|
65
|
+
// `view.move` sets `borrow_fee = calculate_borrow_fee(cumul) +
|
|
66
|
+
// unrealized_borrow_fee`, and `position.move::calculate_funding_fee` returns
|
|
67
|
+
// the unrealized leg combined with the current period's, so the row's
|
|
68
|
+
// `unrealized_*` fields are strict SUBSETS of the combined pair.
|
|
69
|
+
borrowFeeRaw: BigInt(position.borrow_fee),
|
|
70
|
+
fundingSign: position.funding_fee_positive,
|
|
71
|
+
fundingFeeRaw: BigInt(position.funding_fee),
|
|
72
|
+
tradingFeeRaw: BigInt(position.unrealized_trading_fee),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
@@ -7,6 +7,19 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Use `triggerPrice === undefined` (market form) to park an order at
|
|
9
9
|
* tick 0 in the limit book; a keeper picks it up via `match_orders`.
|
|
10
|
+
*
|
|
11
|
+
* ## Trigger prices are exact order-book KEYS
|
|
12
|
+
*
|
|
13
|
+
* Every `triggerPrice` / `currentTriggerPrice` / `newTriggerPrice` below is the
|
|
14
|
+
* raw 1e9-scaled value the book is keyed by — off by a single 1e-9 unit and the
|
|
15
|
+
* lookup silently finds nothing. Build them with `rawPrice` in its EXACT mode
|
|
16
|
+
* (`rawPrice("95000.5")`, an `ExactDecimalUsd` string); the `number` mode
|
|
17
|
+
* round-trips through f64 and is exact only below ≈ $9,007,199.
|
|
18
|
+
*
|
|
19
|
+
* The params stay `bigint | number` (the RAW scaled value, not USD): both are
|
|
20
|
+
* legitimate raw inputs, `toU128` already rejects a non-safe-integer `number`
|
|
21
|
+
* before it can serialize wrong, and dropping `number` would break published
|
|
22
|
+
* call shapes. The mode choice belongs one level up, at `rawPrice`.
|
|
10
23
|
*/
|
|
11
24
|
import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
|
|
12
25
|
import type { PerpClient } from "../client.ts";
|
|
@@ -8,6 +8,19 @@
|
|
|
8
8
|
*
|
|
9
9
|
* Use `triggerPrice === undefined` (market form) to park an order at
|
|
10
10
|
* tick 0 in the limit book; a keeper picks it up via `match_orders`.
|
|
11
|
+
*
|
|
12
|
+
* ## Trigger prices are exact order-book KEYS
|
|
13
|
+
*
|
|
14
|
+
* Every `triggerPrice` / `currentTriggerPrice` / `newTriggerPrice` below is the
|
|
15
|
+
* raw 1e9-scaled value the book is keyed by — off by a single 1e-9 unit and the
|
|
16
|
+
* lookup silently finds nothing. Build them with `rawPrice` in its EXACT mode
|
|
17
|
+
* (`rawPrice("95000.5")`, an `ExactDecimalUsd` string); the `number` mode
|
|
18
|
+
* round-trips through f64 and is exact only below ≈ $9,007,199.
|
|
19
|
+
*
|
|
20
|
+
* The params stay `bigint | number` (the RAW scaled value, not USD): both are
|
|
21
|
+
* legitimate raw inputs, `toU128` already rejects a non-safe-integer `number`
|
|
22
|
+
* before it can serialize wrong, and dropping `number` would break published
|
|
23
|
+
* call shapes. The mode choice belongs one level up, at `rawPrice`.
|
|
11
24
|
*/
|
|
12
25
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
13
26
|
if (k2 === undefined) k2 = k;
|
|
@@ -52,6 +65,7 @@ exports.addPreOrderRequest = addPreOrderRequest;
|
|
|
52
65
|
const account_request_ts_1 = require("../../account/account-request.js");
|
|
53
66
|
const request_ts_1 = require("../../generated/waterx_perp/request.js");
|
|
54
67
|
const trading = __importStar(require("../../generated/waterx_perp/trading.js"));
|
|
68
|
+
const validate_ts_1 = require("../../utils/validate.js");
|
|
55
69
|
const constants_ts_1 = require("../constants.js");
|
|
56
70
|
/** Build a `request::PlaceOrderArgument` Move struct in the PTB. */
|
|
57
71
|
function buildPlaceOrderArgument(client, tx, p) {
|
|
@@ -61,11 +75,11 @@ function buildPlaceOrderArgument(client, tx, p) {
|
|
|
61
75
|
isLong: p.isLong,
|
|
62
76
|
isStopOrder: p.isStopOrder,
|
|
63
77
|
reduceOnly: p.reduceOnly,
|
|
64
|
-
size: p.size,
|
|
65
|
-
triggerPrice: p.triggerPrice
|
|
66
|
-
linkedPositionId: p.linkedPositionId
|
|
67
|
-
acceptablePrice: p.acceptablePrice
|
|
68
|
-
collateralAmount: p.collateralAmount,
|
|
78
|
+
size: (0, validate_ts_1.toU128)(p.size, "size"),
|
|
79
|
+
triggerPrice: (0, validate_ts_1.toU128OrNull)(p.triggerPrice, "triggerPrice"),
|
|
80
|
+
linkedPositionId: (0, validate_ts_1.toU64OrNull)(p.linkedPositionId, "linkedPositionId"),
|
|
81
|
+
acceptablePrice: (0, validate_ts_1.toU64OrNull)(p.acceptablePrice, "acceptablePrice"),
|
|
82
|
+
collateralAmount: (0, validate_ts_1.toU64)(p.collateralAmount, "collateralAmount"),
|
|
69
83
|
},
|
|
70
84
|
})(tx);
|
|
71
85
|
return arg;
|
|
@@ -107,9 +121,9 @@ function cancelOrderRequest(client, tx, params) {
|
|
|
107
121
|
ticker: params.ticker,
|
|
108
122
|
senderRequest: req,
|
|
109
123
|
accountId: params.accountId,
|
|
110
|
-
orderId: params.orderId,
|
|
111
|
-
triggerPrice: params.triggerPrice ?? 0n,
|
|
112
|
-
orderTypeTag: params.orderTypeTag ?? constants_ts_1.ORDER_TAG_WILDCARD,
|
|
124
|
+
orderId: (0, validate_ts_1.toU64)(params.orderId, "orderId"),
|
|
125
|
+
triggerPrice: (0, validate_ts_1.toU128)(params.triggerPrice ?? 0n, "triggerPrice"),
|
|
126
|
+
orderTypeTag: (0, validate_ts_1.toU8)(params.orderTypeTag ?? constants_ts_1.ORDER_TAG_WILDCARD, "orderTypeTag"),
|
|
113
127
|
},
|
|
114
128
|
typeArguments: [params.collateralType, params.lpType ?? client.wlpType()],
|
|
115
129
|
})(tx);
|
|
@@ -126,11 +140,11 @@ function updateOrderRequest(client, tx, params) {
|
|
|
126
140
|
ticker: params.ticker,
|
|
127
141
|
senderRequest: req,
|
|
128
142
|
accountId: params.accountId,
|
|
129
|
-
orderId: params.orderId,
|
|
130
|
-
currentTriggerPrice: params.currentTriggerPrice,
|
|
131
|
-
orderTypeTag: params.orderTypeTag,
|
|
132
|
-
newSize: params.newSize,
|
|
133
|
-
newTriggerPrice: params.newTriggerPrice,
|
|
143
|
+
orderId: (0, validate_ts_1.toU64)(params.orderId, "orderId"),
|
|
144
|
+
currentTriggerPrice: (0, validate_ts_1.toU128)(params.currentTriggerPrice, "currentTriggerPrice"),
|
|
145
|
+
orderTypeTag: (0, validate_ts_1.toU8)(params.orderTypeTag, "orderTypeTag"),
|
|
146
|
+
newSize: (0, validate_ts_1.toU128)(params.newSize, "newSize"),
|
|
147
|
+
newTriggerPrice: (0, validate_ts_1.toU128)(params.newTriggerPrice, "newTriggerPrice"),
|
|
134
148
|
},
|
|
135
149
|
typeArguments: [params.collateralType, params.lpType ?? client.wlpType()],
|
|
136
150
|
})(tx);
|
|
@@ -147,8 +161,8 @@ function cancelPreOrderRequest(client, tx, params) {
|
|
|
147
161
|
ticker: params.ticker,
|
|
148
162
|
senderRequest: req,
|
|
149
163
|
accountId: params.accountId,
|
|
150
|
-
mainOrderId: params.mainOrderId,
|
|
151
|
-
preOrderId: params.preOrderId,
|
|
164
|
+
mainOrderId: (0, validate_ts_1.toU64)(params.mainOrderId, "mainOrderId"),
|
|
165
|
+
preOrderId: (0, validate_ts_1.toU64)(params.preOrderId, "preOrderId"),
|
|
152
166
|
},
|
|
153
167
|
typeArguments: [params.collateralType, params.lpType ?? client.wlpType()],
|
|
154
168
|
})(tx);
|
|
@@ -166,7 +180,7 @@ function addPreOrderRequest(client, tx, params) {
|
|
|
166
180
|
ticker: params.ticker,
|
|
167
181
|
senderRequest: req,
|
|
168
182
|
accountId: params.accountId,
|
|
169
|
-
mainOrderId: params.mainOrderId,
|
|
183
|
+
mainOrderId: (0, validate_ts_1.toU64)(params.mainOrderId, "mainOrderId"),
|
|
170
184
|
preOrder: preArg,
|
|
171
185
|
},
|
|
172
186
|
typeArguments: [params.collateralType, params.lpType ?? client.wlpType()],
|
|
@@ -55,6 +55,7 @@ exports.unstake = unstake;
|
|
|
55
55
|
exports.claimReward = claimReward;
|
|
56
56
|
const account_request_ts_1 = require("../../account/account-request.js");
|
|
57
57
|
const staking = __importStar(require("../../generated/waterx_staking/waterx_staking.js"));
|
|
58
|
+
const validate_ts_1 = require("../../utils/validate.js");
|
|
58
59
|
function pool(client, stakeAlias) {
|
|
59
60
|
const id = client.config.packages.waterx_staking?.pools?.[stakeAlias];
|
|
60
61
|
if (!id) {
|
|
@@ -79,7 +80,7 @@ function stake(client, tx, params) {
|
|
|
79
80
|
wxaRegistry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
80
81
|
accountId: params.accountId,
|
|
81
82
|
accReq: req,
|
|
82
|
-
stakeAmount: params.stakeAmount,
|
|
83
|
+
stakeAmount: (0, validate_ts_1.toU64Arg)(params.stakeAmount, "stakeAmount"),
|
|
83
84
|
},
|
|
84
85
|
typeArguments: [params.stakeType],
|
|
85
86
|
})(tx);
|
|
@@ -110,7 +111,7 @@ function unstake(client, tx, params) {
|
|
|
110
111
|
wxaRegistry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
111
112
|
accountId: params.accountId,
|
|
112
113
|
accReq: req,
|
|
113
|
-
withdrawalAmount: params.withdrawalAmount,
|
|
114
|
+
withdrawalAmount: (0, validate_ts_1.toU64Arg)(params.withdrawalAmount, "withdrawalAmount"),
|
|
114
115
|
},
|
|
115
116
|
typeArguments: [params.stakeType],
|
|
116
117
|
})(tx);
|
|
@@ -60,6 +60,7 @@ exports.openPositionByKeeper = openPositionByKeeper;
|
|
|
60
60
|
exports.closePositionByKeeper = closePositionByKeeper;
|
|
61
61
|
const account_request_ts_1 = require("../../account/account-request.js");
|
|
62
62
|
const trading = __importStar(require("../../generated/waterx_perp/trading.js"));
|
|
63
|
+
const validate_ts_1 = require("../../utils/validate.js");
|
|
63
64
|
const constants_ts_1 = require("../constants.js");
|
|
64
65
|
function typeArgs(client, t) {
|
|
65
66
|
return [t.collateralType, t.lpType ?? client.wlpType()];
|
|
@@ -87,8 +88,8 @@ function closePositionRequest(client, tx, params) {
|
|
|
87
88
|
ticker: params.ticker,
|
|
88
89
|
senderRequest: req,
|
|
89
90
|
accountId: params.accountId,
|
|
90
|
-
positionId: params.positionId,
|
|
91
|
-
acceptablePrice: params.acceptablePrice,
|
|
91
|
+
positionId: (0, validate_ts_1.toU64)(params.positionId, "positionId"),
|
|
92
|
+
acceptablePrice: (0, validate_ts_1.toU64)(params.acceptablePrice, "acceptablePrice"),
|
|
92
93
|
},
|
|
93
94
|
typeArguments: typeArgs(client, params),
|
|
94
95
|
})(tx);
|
|
@@ -106,11 +107,11 @@ function increasePositionRequest(client, tx, params) {
|
|
|
106
107
|
ticker: params.ticker,
|
|
107
108
|
senderRequest: req,
|
|
108
109
|
accountId: params.accountId,
|
|
109
|
-
orderId: params.orderId
|
|
110
|
-
positionId: params.positionId,
|
|
111
|
-
collateralAmount: params.collateralAmount,
|
|
112
|
-
size: params.size,
|
|
113
|
-
acceptablePrice: params.acceptablePrice,
|
|
110
|
+
orderId: (0, validate_ts_1.toU64OrNull)(params.orderId, "orderId"),
|
|
111
|
+
positionId: (0, validate_ts_1.toU64)(params.positionId, "positionId"),
|
|
112
|
+
collateralAmount: (0, validate_ts_1.toU64)(params.collateralAmount, "collateralAmount"),
|
|
113
|
+
size: (0, validate_ts_1.toU128)(params.size, "size"),
|
|
114
|
+
acceptablePrice: (0, validate_ts_1.toU64)(params.acceptablePrice, "acceptablePrice"),
|
|
114
115
|
},
|
|
115
116
|
typeArguments: typeArgs(client, params),
|
|
116
117
|
})(tx);
|
|
@@ -128,9 +129,9 @@ function decreasePositionRequest(client, tx, params) {
|
|
|
128
129
|
ticker: params.ticker,
|
|
129
130
|
senderRequest: req,
|
|
130
131
|
accountId: params.accountId,
|
|
131
|
-
positionId: params.positionId,
|
|
132
|
-
size: params.size,
|
|
133
|
-
acceptablePrice: params.acceptablePrice,
|
|
132
|
+
positionId: (0, validate_ts_1.toU64)(params.positionId, "positionId"),
|
|
133
|
+
size: (0, validate_ts_1.toU128)(params.size, "size"),
|
|
134
|
+
acceptablePrice: (0, validate_ts_1.toU64)(params.acceptablePrice, "acceptablePrice"),
|
|
134
135
|
},
|
|
135
136
|
typeArguments: typeArgs(client, params),
|
|
136
137
|
})(tx);
|
|
@@ -148,8 +149,8 @@ function depositCollateralRequest(client, tx, params) {
|
|
|
148
149
|
ticker: params.ticker,
|
|
149
150
|
senderRequest: req,
|
|
150
151
|
accountId: params.accountId,
|
|
151
|
-
positionId: params.positionId,
|
|
152
|
-
collateralAmount: params.collateralAmount,
|
|
152
|
+
positionId: (0, validate_ts_1.toU64)(params.positionId, "positionId"),
|
|
153
|
+
collateralAmount: (0, validate_ts_1.toU64)(params.collateralAmount, "collateralAmount"),
|
|
153
154
|
},
|
|
154
155
|
typeArguments: typeArgs(client, params),
|
|
155
156
|
})(tx);
|
|
@@ -167,8 +168,8 @@ function withdrawCollateralRequest(client, tx, params) {
|
|
|
167
168
|
ticker: params.ticker,
|
|
168
169
|
senderRequest: req,
|
|
169
170
|
accountId: params.accountId,
|
|
170
|
-
positionId: params.positionId,
|
|
171
|
-
amount: params.amount,
|
|
171
|
+
positionId: (0, validate_ts_1.toU64)(params.positionId, "positionId"),
|
|
172
|
+
amount: (0, validate_ts_1.toU64)(params.amount, "amount"),
|
|
172
173
|
},
|
|
173
174
|
typeArguments: typeArgs(client, params),
|
|
174
175
|
})(tx);
|
|
@@ -202,7 +203,7 @@ function liquidate(client, tx, params) {
|
|
|
202
203
|
ticker: params.ticker,
|
|
203
204
|
pool: tx.object(obj.wlpPool),
|
|
204
205
|
senderRequest: req,
|
|
205
|
-
positionId: params.positionId,
|
|
206
|
+
positionId: (0, validate_ts_1.toU64)(params.positionId, "positionId"),
|
|
206
207
|
oracle: tx.object(obj.oracle),
|
|
207
208
|
},
|
|
208
209
|
typeArguments: typeArgs(client, params),
|
|
@@ -221,8 +222,8 @@ function batchLiquidate(client, tx, params) {
|
|
|
221
222
|
pool: tx.object(obj.wlpPool),
|
|
222
223
|
senderRequest: req,
|
|
223
224
|
oracle: tx.object(obj.oracle),
|
|
224
|
-
pageSize: params.pageSize,
|
|
225
|
-
pageIndex: params.pageIndex,
|
|
225
|
+
pageSize: (0, validate_ts_1.toU64)(params.pageSize, "pageSize"),
|
|
226
|
+
pageIndex: (0, validate_ts_1.toU64)(params.pageIndex, "pageIndex"),
|
|
226
227
|
},
|
|
227
228
|
typeArguments: typeArgs(client, params),
|
|
228
229
|
})(tx);
|
|
@@ -240,9 +241,9 @@ function matchOrders(client, tx, params) {
|
|
|
240
241
|
pool: tx.object(obj.wlpPool),
|
|
241
242
|
senderRequest: req,
|
|
242
243
|
oracle: tx.object(obj.oracle),
|
|
243
|
-
orderTypeTag: params.orderTypeTag,
|
|
244
|
-
triggerPrice: params.triggerPrice,
|
|
245
|
-
maxFills: params.maxFills,
|
|
244
|
+
orderTypeTag: (0, validate_ts_1.toU8)(params.orderTypeTag, "orderTypeTag"),
|
|
245
|
+
triggerPrice: (0, validate_ts_1.toU128)(params.triggerPrice, "triggerPrice"),
|
|
246
|
+
maxFills: (0, validate_ts_1.toU64)(params.maxFills, "maxFills"),
|
|
246
247
|
},
|
|
247
248
|
typeArguments: typeArgs(client, params),
|
|
248
249
|
})(tx);
|
|
@@ -278,8 +279,8 @@ function openPositionByKeeper(client, tx, params) {
|
|
|
278
279
|
accountObjectAddress: params.accountObjectAddress,
|
|
279
280
|
collateralCoin: params.collateralCoin,
|
|
280
281
|
isLong: params.isLong,
|
|
281
|
-
size: params.size,
|
|
282
|
-
acceptablePrice: params.acceptablePrice,
|
|
282
|
+
size: (0, validate_ts_1.toU128)(params.size, "size"),
|
|
283
|
+
acceptablePrice: (0, validate_ts_1.toU64)(params.acceptablePrice, "acceptablePrice"),
|
|
283
284
|
oracle: tx.object(obj.oracle),
|
|
284
285
|
},
|
|
285
286
|
typeArguments: typeArgs(client, params),
|
|
@@ -297,8 +298,8 @@ function closePositionByKeeper(client, tx, params) {
|
|
|
297
298
|
ticker: params.ticker,
|
|
298
299
|
pool: tx.object(obj.wlpPool),
|
|
299
300
|
keeperRequest: req,
|
|
300
|
-
positionId: params.positionId,
|
|
301
|
-
acceptablePrice: params.acceptablePrice,
|
|
301
|
+
positionId: (0, validate_ts_1.toU64)(params.positionId, "positionId"),
|
|
302
|
+
acceptablePrice: (0, validate_ts_1.toU64)(params.acceptablePrice, "acceptablePrice"),
|
|
302
303
|
oracle: tx.object(obj.oracle),
|
|
303
304
|
},
|
|
304
305
|
typeArguments: typeArgs(client, params),
|