@waterx/sdk 4.0.1 → 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 +25 -10
- package/dist/cjs/src/account/account.js +2 -1
- 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 +2 -0
- package/dist/cjs/src/oracle/aggregate.js +27 -2
- package/dist/cjs/src/oracle/config.d.ts +75 -0
- package/dist/cjs/src/oracle/config.js +15 -1
- package/dist/cjs/src/oracle/host.d.ts +12 -1
- package/dist/cjs/src/oracle/index.d.ts +2 -0
- package/dist/cjs/src/oracle/index.js +6 -1
- package/dist/cjs/src/oracle/price-update-rule.d.ts +3 -4
- package/dist/cjs/src/oracle/rule-registry.d.ts +8 -7
- package/dist/cjs/src/oracle/rule-registry.js +10 -7
- 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/perp/client.d.ts +44 -6
- package/dist/cjs/src/perp/client.js +14 -0
- package/dist/cjs/src/perp/config.d.ts +2 -3
- package/dist/cjs/src/perp/config.js +2 -1
- 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 +6 -2
- package/dist/cjs/src/perp/index.js +12 -6
- 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 +31 -10
- package/dist/cjs/src/unified-client.js +2 -0
- 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/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 +2 -0
- package/dist/src/oracle/aggregate.js +27 -2
- package/dist/src/oracle/config.d.ts +75 -0
- package/dist/src/oracle/config.js +14 -0
- package/dist/src/oracle/host.d.ts +12 -1
- package/dist/src/oracle/index.d.ts +2 -0
- package/dist/src/oracle/index.js +3 -0
- package/dist/src/oracle/price-update-rule.d.ts +3 -4
- package/dist/src/oracle/rule-registry.d.ts +8 -7
- package/dist/src/oracle/rule-registry.js +10 -7
- package/dist/src/oracle/rules/waterx-rule.d.ts +89 -0
- package/dist/src/oracle/rules/waterx-rule.js +266 -0
- package/dist/src/perp/client.d.ts +44 -6
- package/dist/src/perp/client.js +15 -1
- package/dist/src/perp/config.d.ts +2 -3
- package/dist/src/perp/config.js +1 -1
- 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 +6 -2
- package/dist/src/perp/index.js +4 -2
- 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 +31 -10
- package/dist/src/unified-client.js +2 -0
- 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
|
@@ -5,8 +5,16 @@
|
|
|
5
5
|
import { bcs } from "@mysten/sui/bcs";
|
|
6
6
|
import { Transaction } from "@mysten/sui/transactions";
|
|
7
7
|
import { getAccountOrders as getAccountOrdersCall, getAccountPositions as getAccountPositionsCall, getMarketOrders as getMarketOrdersCall, getMarketPositions as getMarketPositionsCall, getRedeemRequests as getRedeemRequestsCall, OrderData, orderData as orderDataCall, PositionData, positionData as positionDataCall, positionExists as positionExistsCall, RedeemRequestData, } from "../../generated/waterx_perp_view/view.js";
|
|
8
|
+
import { parseWholeDollarU64, toU8, toU64, toU128, } from "../../utils/validate.js";
|
|
8
9
|
import { DRY_RUN_SENDER } from "../constants.js";
|
|
9
10
|
import { simulateAndExtract, toBytes, withLp } from "./simulate.js";
|
|
11
|
+
// The whole-dollar USD price domain is a pure numeric guard with no chain/fetch
|
|
12
|
+
// dependency, so it lives with the rest of that vocabulary in
|
|
13
|
+
// `utils/validate.ts`. It is re-exported HERE — unchanged — because this module
|
|
14
|
+
// is its published home: `perp/fetch` → `@waterx/sdk`. Every read param below
|
|
15
|
+
// is typed `WholeDollarUsdPrice`, so the type and its parser stay one hop from
|
|
16
|
+
// the functions that consume them.
|
|
17
|
+
export { parseWholeDollarU64 };
|
|
10
18
|
export async function positionExists(client, args) {
|
|
11
19
|
const tx = new Transaction();
|
|
12
20
|
positionExistsCall({
|
|
@@ -14,7 +22,7 @@ export async function positionExists(client, args) {
|
|
|
14
22
|
arguments: {
|
|
15
23
|
marketRegistry: tx.object(client.config.packages.waterx_perp.market_registry_wlp),
|
|
16
24
|
ticker: args.ticker,
|
|
17
|
-
positionId: args.positionId,
|
|
25
|
+
positionId: toU64(args.positionId, "positionId"),
|
|
18
26
|
},
|
|
19
27
|
typeArguments: [withLp(client, args.lpType)],
|
|
20
28
|
})(tx);
|
|
@@ -29,9 +37,9 @@ export async function getPosition(client, args) {
|
|
|
29
37
|
marketRegistry: tx.object(client.config.packages.waterx_perp.market_registry_wlp),
|
|
30
38
|
ticker: args.ticker,
|
|
31
39
|
pool: tx.object(client.config.packages.wlp.wlp_pool),
|
|
32
|
-
basePriceUsd: args.basePriceUsd,
|
|
33
|
-
collateralPriceUsd: args.collateralPriceUsd,
|
|
34
|
-
positionId: args.positionId,
|
|
40
|
+
basePriceUsd: toU64(args.basePriceUsd, "basePriceUsd"),
|
|
41
|
+
collateralPriceUsd: toU64(args.collateralPriceUsd, "collateralPriceUsd"),
|
|
42
|
+
positionId: toU64(args.positionId, "positionId"),
|
|
35
43
|
},
|
|
36
44
|
typeArguments: [withLp(client, args.lpType)],
|
|
37
45
|
})(tx);
|
|
@@ -44,10 +52,10 @@ export async function getOrder(client, args) {
|
|
|
44
52
|
arguments: {
|
|
45
53
|
marketRegistry: tx.object(client.config.packages.waterx_perp.market_registry_wlp),
|
|
46
54
|
ticker: args.ticker,
|
|
47
|
-
basePriceUsd: args.basePriceUsd,
|
|
48
|
-
orderTypeTag: args.orderTypeTag,
|
|
49
|
-
triggerPrice: args.triggerPrice,
|
|
50
|
-
orderId: args.orderId,
|
|
55
|
+
basePriceUsd: toU64(args.basePriceUsd, "basePriceUsd"),
|
|
56
|
+
orderTypeTag: toU8(args.orderTypeTag, "orderTypeTag"),
|
|
57
|
+
triggerPrice: toU128(args.triggerPrice, "triggerPrice"),
|
|
58
|
+
orderId: toU64(args.orderId, "orderId"),
|
|
51
59
|
},
|
|
52
60
|
typeArguments: [withLp(client, args.lpType)],
|
|
53
61
|
})(tx);
|
|
@@ -60,9 +68,9 @@ export async function getMarketOrders(client, args) {
|
|
|
60
68
|
arguments: {
|
|
61
69
|
marketRegistry: tx.object(client.config.packages.waterx_perp.market_registry_wlp),
|
|
62
70
|
ticker: args.ticker,
|
|
63
|
-
basePriceUsd: args.basePriceUsd ?? 0n,
|
|
64
|
-
cursor: args.cursor ?? 0n,
|
|
65
|
-
pageSize: args.pageSize ?? 100n,
|
|
71
|
+
basePriceUsd: toU64(args.basePriceUsd ?? 0n, "basePriceUsd"),
|
|
72
|
+
cursor: toU64(args.cursor ?? 0n, "cursor"),
|
|
73
|
+
pageSize: toU64(args.pageSize ?? 100n, "pageSize"),
|
|
66
74
|
},
|
|
67
75
|
typeArguments: [withLp(client, args.lpType)],
|
|
68
76
|
})(tx);
|
|
@@ -94,10 +102,10 @@ export async function getMarketPositions(client, args) {
|
|
|
94
102
|
marketRegistry: tx.object(client.config.packages.waterx_perp.market_registry_wlp),
|
|
95
103
|
ticker: args.ticker,
|
|
96
104
|
pool: tx.object(client.config.packages.wlp.wlp_pool),
|
|
97
|
-
basePriceUsd: args.basePriceUsd,
|
|
98
|
-
collateralPriceUsd: args.collateralPriceUsd ?? 0n,
|
|
99
|
-
cursor: args.cursor ?? 0n,
|
|
100
|
-
pageSize: args.pageSize ?? 100n,
|
|
105
|
+
basePriceUsd: toU64(args.basePriceUsd, "basePriceUsd"),
|
|
106
|
+
collateralPriceUsd: toU64(args.collateralPriceUsd ?? 0n, "collateralPriceUsd"),
|
|
107
|
+
cursor: toU64(args.cursor ?? 0n, "cursor"),
|
|
108
|
+
pageSize: toU64(args.pageSize ?? 100n, "pageSize"),
|
|
101
109
|
},
|
|
102
110
|
typeArguments: [withLp(client, args.lpType)],
|
|
103
111
|
})(tx);
|
|
@@ -130,8 +138,8 @@ export async function getAccountPositions(client, args) {
|
|
|
130
138
|
ticker: args.ticker,
|
|
131
139
|
pool: tx.object(client.config.packages.wlp.wlp_pool),
|
|
132
140
|
wxaRegistry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
133
|
-
basePriceUsd: args.basePriceUsd,
|
|
134
|
-
collateralPriceUsd: args.collateralPriceUsd ?? 0n,
|
|
141
|
+
basePriceUsd: toU64(args.basePriceUsd, "basePriceUsd"),
|
|
142
|
+
collateralPriceUsd: toU64(args.collateralPriceUsd ?? 0n, "collateralPriceUsd"),
|
|
135
143
|
accountObjectAddress: args.accountObjectAddress,
|
|
136
144
|
},
|
|
137
145
|
typeArguments: [withLp(client, args.lpType)],
|
|
@@ -145,7 +153,7 @@ export async function getAccountOrders(client, args) {
|
|
|
145
153
|
arguments: {
|
|
146
154
|
marketRegistry: tx.object(client.config.packages.waterx_perp.market_registry_wlp),
|
|
147
155
|
ticker: args.ticker,
|
|
148
|
-
basePriceUsd: args.basePriceUsd ?? 0n,
|
|
156
|
+
basePriceUsd: toU64(args.basePriceUsd ?? 0n, "basePriceUsd"),
|
|
149
157
|
accountObjectAddress: args.accountObjectAddress,
|
|
150
158
|
},
|
|
151
159
|
typeArguments: [withLp(client, args.lpType)],
|
|
@@ -158,8 +166,8 @@ export async function getRedeemRequests(client, args = {}) {
|
|
|
158
166
|
package: client.config.packages.waterx_perp_view.published_at,
|
|
159
167
|
arguments: {
|
|
160
168
|
pool: tx.object(client.config.packages.wlp.wlp_pool),
|
|
161
|
-
cursor: args.cursor ?? 0n,
|
|
162
|
-
pageSize: args.pageSize ?? 100n,
|
|
169
|
+
cursor: toU64(args.cursor ?? 0n, "cursor"),
|
|
170
|
+
pageSize: toU64(args.pageSize ?? 100n, "pageSize"),
|
|
163
171
|
},
|
|
164
172
|
typeArguments: [withLp(client, args.lpType)],
|
|
165
173
|
})(tx);
|
package/dist/src/perp/index.d.ts
CHANGED
|
@@ -2,10 +2,14 @@ export { PerpClient } from "./client.ts";
|
|
|
2
2
|
export type { CreateClientOptions } from "./client.ts";
|
|
3
3
|
export { PYTH_DEFAULTS, WORMHOLE_DEFAULTS, clearConfigCache, loadConfig } from "./config.ts";
|
|
4
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,
|
|
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";
|
package/dist/src/perp/index.js
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
export { PerpClient } from "./client.js";
|
|
3
3
|
export { PYTH_DEFAULTS, WORMHOLE_DEFAULTS, clearConfigCache, loadConfig } from "./config.js";
|
|
4
4
|
// ======== Constants & enums ========
|
|
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,
|
|
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.js";
|
|
6
6
|
// ======== Utilities ========
|
|
7
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";
|
|
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.js";
|
|
9
|
+
export { formatFundingInterval } from "../utils/format.js";
|
|
10
|
+
export { calcEstLiqPriceRawFromView } from "./liq-view.js";
|
|
9
11
|
// ======== Transaction builders (user-side) ========
|
|
10
12
|
export * from "./user/index.js";
|
|
11
13
|
// ======== 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,71 @@
|
|
|
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 { calcEstLiqPriceRaw } from "../utils/math.js";
|
|
23
|
+
/**
|
|
24
|
+
* Estimated liquidation price from a fetched `PositionDataView` row —
|
|
25
|
+
* bit-identical to that row's `est_liq_price`.
|
|
26
|
+
*
|
|
27
|
+
* Maps the row's nine raw fields onto {@link calcEstLiqPriceRaw} (the op-for-op
|
|
28
|
+
* mirror of `view.move::calculate_est_liq_price`) and takes the remaining
|
|
29
|
+
* three — the two probe prices plus the market's maintenance margin — from
|
|
30
|
+
* `opts`. Returns the raw 1e9-scaled u128 price; `0n` = already liquidatable /
|
|
31
|
+
* zero size.
|
|
32
|
+
*
|
|
33
|
+
* ## INVARIANT — the prices must be the ones the row was READ AT
|
|
34
|
+
*
|
|
35
|
+
* `opts.basePriceUsd` / `opts.collateralPriceUsd` MUST be the same whole-dollar
|
|
36
|
+
* values you passed to the `perp/fetch` read that produced `position`
|
|
37
|
+
* (`getPosition`, `getMarketPositions`, `getAccountPositions`, …).
|
|
38
|
+
*
|
|
39
|
+
* `PositionDataView` does NOT carry the probe prices it was computed at, so
|
|
40
|
+
* NOTHING — not this adapter, not the type system — can check this for you.
|
|
41
|
+
* Feed different prices and the row's fee / notional-derived fields were
|
|
42
|
+
* computed against one price while the estimate is computed against another:
|
|
43
|
+
* the result is a plausible-looking number that silently disagrees with
|
|
44
|
+
* `position.est_liq_price`. Thread the prices through from the read call site;
|
|
45
|
+
* never re-fetch or re-guess them here.
|
|
46
|
+
*
|
|
47
|
+
* @throws RangeError via `calcEstLiqPriceRaw` when any raw value is negative or
|
|
48
|
+
* `collateral_decimal` is outside `[0, 19]`.
|
|
49
|
+
*/
|
|
50
|
+
export function calcEstLiqPriceRawFromView(position, opts) {
|
|
51
|
+
return calcEstLiqPriceRaw({
|
|
52
|
+
isLong: position.is_long,
|
|
53
|
+
sizeRaw: BigInt(position.size),
|
|
54
|
+
avgPriceRaw: BigInt(position.average_price),
|
|
55
|
+
collateralAmountRaw: BigInt(position.collateral_amount),
|
|
56
|
+
collateralDecimal: position.collateral_decimal,
|
|
57
|
+
basePriceUsd: opts.basePriceUsd,
|
|
58
|
+
collateralPriceUsd: opts.collateralPriceUsd,
|
|
59
|
+
maintenanceMarginRaw: opts.maintenanceMarginRaw,
|
|
60
|
+
// The view pre-combines accrued + unrealized into `borrow_fee` / `funding_fee`
|
|
61
|
+
// — take those, NOT the `unrealized_*` pair, which would UNDER-count:
|
|
62
|
+
// `view.move` sets `borrow_fee = calculate_borrow_fee(cumul) +
|
|
63
|
+
// unrealized_borrow_fee`, and `position.move::calculate_funding_fee` returns
|
|
64
|
+
// the unrealized leg combined with the current period's, so the row's
|
|
65
|
+
// `unrealized_*` fields are strict SUBSETS of the combined pair.
|
|
66
|
+
borrowFeeRaw: BigInt(position.borrow_fee),
|
|
67
|
+
fundingSign: position.funding_fee_positive,
|
|
68
|
+
fundingFeeRaw: BigInt(position.funding_fee),
|
|
69
|
+
tradingFeeRaw: BigInt(position.unrealized_trading_fee),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
@@ -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";
|
|
@@ -7,10 +7,24 @@
|
|
|
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 { makeSenderRequest } from "../../account/account-request.js";
|
|
12
25
|
import { newPlaceOrderArgument } from "../../generated/waterx_perp/request.js";
|
|
13
26
|
import * as trading from "../../generated/waterx_perp/trading.js";
|
|
27
|
+
import { toU8, toU64, toU64OrNull, toU128, toU128OrNull } from "../../utils/validate.js";
|
|
14
28
|
import { ORDER_TAG_WILDCARD } from "../constants.js";
|
|
15
29
|
/** Build a `request::PlaceOrderArgument` Move struct in the PTB. */
|
|
16
30
|
export function buildPlaceOrderArgument(client, tx, p) {
|
|
@@ -20,11 +34,11 @@ export function buildPlaceOrderArgument(client, tx, p) {
|
|
|
20
34
|
isLong: p.isLong,
|
|
21
35
|
isStopOrder: p.isStopOrder,
|
|
22
36
|
reduceOnly: p.reduceOnly,
|
|
23
|
-
size: p.size,
|
|
24
|
-
triggerPrice: p.triggerPrice
|
|
25
|
-
linkedPositionId: p.linkedPositionId
|
|
26
|
-
acceptablePrice: p.acceptablePrice
|
|
27
|
-
collateralAmount: p.collateralAmount,
|
|
37
|
+
size: toU128(p.size, "size"),
|
|
38
|
+
triggerPrice: toU128OrNull(p.triggerPrice, "triggerPrice"),
|
|
39
|
+
linkedPositionId: toU64OrNull(p.linkedPositionId, "linkedPositionId"),
|
|
40
|
+
acceptablePrice: toU64OrNull(p.acceptablePrice, "acceptablePrice"),
|
|
41
|
+
collateralAmount: toU64(p.collateralAmount, "collateralAmount"),
|
|
28
42
|
},
|
|
29
43
|
})(tx);
|
|
30
44
|
return arg;
|
|
@@ -66,9 +80,9 @@ export function cancelOrderRequest(client, tx, params) {
|
|
|
66
80
|
ticker: params.ticker,
|
|
67
81
|
senderRequest: req,
|
|
68
82
|
accountId: params.accountId,
|
|
69
|
-
orderId: params.orderId,
|
|
70
|
-
triggerPrice: params.triggerPrice ?? 0n,
|
|
71
|
-
orderTypeTag: params.orderTypeTag ?? ORDER_TAG_WILDCARD,
|
|
83
|
+
orderId: toU64(params.orderId, "orderId"),
|
|
84
|
+
triggerPrice: toU128(params.triggerPrice ?? 0n, "triggerPrice"),
|
|
85
|
+
orderTypeTag: toU8(params.orderTypeTag ?? ORDER_TAG_WILDCARD, "orderTypeTag"),
|
|
72
86
|
},
|
|
73
87
|
typeArguments: [params.collateralType, params.lpType ?? client.wlpType()],
|
|
74
88
|
})(tx);
|
|
@@ -85,11 +99,11 @@ export function updateOrderRequest(client, tx, params) {
|
|
|
85
99
|
ticker: params.ticker,
|
|
86
100
|
senderRequest: req,
|
|
87
101
|
accountId: params.accountId,
|
|
88
|
-
orderId: params.orderId,
|
|
89
|
-
currentTriggerPrice: params.currentTriggerPrice,
|
|
90
|
-
orderTypeTag: params.orderTypeTag,
|
|
91
|
-
newSize: params.newSize,
|
|
92
|
-
newTriggerPrice: params.newTriggerPrice,
|
|
102
|
+
orderId: toU64(params.orderId, "orderId"),
|
|
103
|
+
currentTriggerPrice: toU128(params.currentTriggerPrice, "currentTriggerPrice"),
|
|
104
|
+
orderTypeTag: toU8(params.orderTypeTag, "orderTypeTag"),
|
|
105
|
+
newSize: toU128(params.newSize, "newSize"),
|
|
106
|
+
newTriggerPrice: toU128(params.newTriggerPrice, "newTriggerPrice"),
|
|
93
107
|
},
|
|
94
108
|
typeArguments: [params.collateralType, params.lpType ?? client.wlpType()],
|
|
95
109
|
})(tx);
|
|
@@ -106,8 +120,8 @@ export function cancelPreOrderRequest(client, tx, params) {
|
|
|
106
120
|
ticker: params.ticker,
|
|
107
121
|
senderRequest: req,
|
|
108
122
|
accountId: params.accountId,
|
|
109
|
-
mainOrderId: params.mainOrderId,
|
|
110
|
-
preOrderId: params.preOrderId,
|
|
123
|
+
mainOrderId: toU64(params.mainOrderId, "mainOrderId"),
|
|
124
|
+
preOrderId: toU64(params.preOrderId, "preOrderId"),
|
|
111
125
|
},
|
|
112
126
|
typeArguments: [params.collateralType, params.lpType ?? client.wlpType()],
|
|
113
127
|
})(tx);
|
|
@@ -125,7 +139,7 @@ export function addPreOrderRequest(client, tx, params) {
|
|
|
125
139
|
ticker: params.ticker,
|
|
126
140
|
senderRequest: req,
|
|
127
141
|
accountId: params.accountId,
|
|
128
|
-
mainOrderId: params.mainOrderId,
|
|
142
|
+
mainOrderId: toU64(params.mainOrderId, "mainOrderId"),
|
|
129
143
|
preOrder: preArg,
|
|
130
144
|
},
|
|
131
145
|
typeArguments: [params.collateralType, params.lpType ?? client.wlpType()],
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { makeSenderRequest } from "../../account/account-request.js";
|
|
19
19
|
import * as staking from "../../generated/waterx_staking/waterx_staking.js";
|
|
20
|
+
import { toU64Arg } from "../../utils/validate.js";
|
|
20
21
|
function pool(client, stakeAlias) {
|
|
21
22
|
const id = client.config.packages.waterx_staking?.pools?.[stakeAlias];
|
|
22
23
|
if (!id) {
|
|
@@ -41,7 +42,7 @@ export function stake(client, tx, params) {
|
|
|
41
42
|
wxaRegistry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
42
43
|
accountId: params.accountId,
|
|
43
44
|
accReq: req,
|
|
44
|
-
stakeAmount: params.stakeAmount,
|
|
45
|
+
stakeAmount: toU64Arg(params.stakeAmount, "stakeAmount"),
|
|
45
46
|
},
|
|
46
47
|
typeArguments: [params.stakeType],
|
|
47
48
|
})(tx);
|
|
@@ -72,7 +73,7 @@ export function unstake(client, tx, params) {
|
|
|
72
73
|
wxaRegistry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
73
74
|
accountId: params.accountId,
|
|
74
75
|
accReq: req,
|
|
75
|
-
withdrawalAmount: params.withdrawalAmount,
|
|
76
|
+
withdrawalAmount: toU64Arg(params.withdrawalAmount, "withdrawalAmount"),
|
|
76
77
|
},
|
|
77
78
|
typeArguments: [params.stakeType],
|
|
78
79
|
})(tx);
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { makeSenderRequest } from "../../account/account-request.js";
|
|
14
14
|
import * as trading from "../../generated/waterx_perp/trading.js";
|
|
15
|
+
import { toU8, toU64, toU64OrNull, toU128 } from "../../utils/validate.js";
|
|
15
16
|
import { ORDER_TAG_WILDCARD } from "../constants.js";
|
|
16
17
|
function typeArgs(client, t) {
|
|
17
18
|
return [t.collateralType, t.lpType ?? client.wlpType()];
|
|
@@ -39,8 +40,8 @@ export function closePositionRequest(client, tx, params) {
|
|
|
39
40
|
ticker: params.ticker,
|
|
40
41
|
senderRequest: req,
|
|
41
42
|
accountId: params.accountId,
|
|
42
|
-
positionId: params.positionId,
|
|
43
|
-
acceptablePrice: params.acceptablePrice,
|
|
43
|
+
positionId: toU64(params.positionId, "positionId"),
|
|
44
|
+
acceptablePrice: toU64(params.acceptablePrice, "acceptablePrice"),
|
|
44
45
|
},
|
|
45
46
|
typeArguments: typeArgs(client, params),
|
|
46
47
|
})(tx);
|
|
@@ -58,11 +59,11 @@ export function increasePositionRequest(client, tx, params) {
|
|
|
58
59
|
ticker: params.ticker,
|
|
59
60
|
senderRequest: req,
|
|
60
61
|
accountId: params.accountId,
|
|
61
|
-
orderId: params.orderId
|
|
62
|
-
positionId: params.positionId,
|
|
63
|
-
collateralAmount: params.collateralAmount,
|
|
64
|
-
size: params.size,
|
|
65
|
-
acceptablePrice: params.acceptablePrice,
|
|
62
|
+
orderId: toU64OrNull(params.orderId, "orderId"),
|
|
63
|
+
positionId: toU64(params.positionId, "positionId"),
|
|
64
|
+
collateralAmount: toU64(params.collateralAmount, "collateralAmount"),
|
|
65
|
+
size: toU128(params.size, "size"),
|
|
66
|
+
acceptablePrice: toU64(params.acceptablePrice, "acceptablePrice"),
|
|
66
67
|
},
|
|
67
68
|
typeArguments: typeArgs(client, params),
|
|
68
69
|
})(tx);
|
|
@@ -80,9 +81,9 @@ export function decreasePositionRequest(client, tx, params) {
|
|
|
80
81
|
ticker: params.ticker,
|
|
81
82
|
senderRequest: req,
|
|
82
83
|
accountId: params.accountId,
|
|
83
|
-
positionId: params.positionId,
|
|
84
|
-
size: params.size,
|
|
85
|
-
acceptablePrice: params.acceptablePrice,
|
|
84
|
+
positionId: toU64(params.positionId, "positionId"),
|
|
85
|
+
size: toU128(params.size, "size"),
|
|
86
|
+
acceptablePrice: toU64(params.acceptablePrice, "acceptablePrice"),
|
|
86
87
|
},
|
|
87
88
|
typeArguments: typeArgs(client, params),
|
|
88
89
|
})(tx);
|
|
@@ -100,8 +101,8 @@ export function depositCollateralRequest(client, tx, params) {
|
|
|
100
101
|
ticker: params.ticker,
|
|
101
102
|
senderRequest: req,
|
|
102
103
|
accountId: params.accountId,
|
|
103
|
-
positionId: params.positionId,
|
|
104
|
-
collateralAmount: params.collateralAmount,
|
|
104
|
+
positionId: toU64(params.positionId, "positionId"),
|
|
105
|
+
collateralAmount: toU64(params.collateralAmount, "collateralAmount"),
|
|
105
106
|
},
|
|
106
107
|
typeArguments: typeArgs(client, params),
|
|
107
108
|
})(tx);
|
|
@@ -119,8 +120,8 @@ export function withdrawCollateralRequest(client, tx, params) {
|
|
|
119
120
|
ticker: params.ticker,
|
|
120
121
|
senderRequest: req,
|
|
121
122
|
accountId: params.accountId,
|
|
122
|
-
positionId: params.positionId,
|
|
123
|
-
amount: params.amount,
|
|
123
|
+
positionId: toU64(params.positionId, "positionId"),
|
|
124
|
+
amount: toU64(params.amount, "amount"),
|
|
124
125
|
},
|
|
125
126
|
typeArguments: typeArgs(client, params),
|
|
126
127
|
})(tx);
|
|
@@ -154,7 +155,7 @@ export function liquidate(client, tx, params) {
|
|
|
154
155
|
ticker: params.ticker,
|
|
155
156
|
pool: tx.object(obj.wlpPool),
|
|
156
157
|
senderRequest: req,
|
|
157
|
-
positionId: params.positionId,
|
|
158
|
+
positionId: toU64(params.positionId, "positionId"),
|
|
158
159
|
oracle: tx.object(obj.oracle),
|
|
159
160
|
},
|
|
160
161
|
typeArguments: typeArgs(client, params),
|
|
@@ -173,8 +174,8 @@ export function batchLiquidate(client, tx, params) {
|
|
|
173
174
|
pool: tx.object(obj.wlpPool),
|
|
174
175
|
senderRequest: req,
|
|
175
176
|
oracle: tx.object(obj.oracle),
|
|
176
|
-
pageSize: params.pageSize,
|
|
177
|
-
pageIndex: params.pageIndex,
|
|
177
|
+
pageSize: toU64(params.pageSize, "pageSize"),
|
|
178
|
+
pageIndex: toU64(params.pageIndex, "pageIndex"),
|
|
178
179
|
},
|
|
179
180
|
typeArguments: typeArgs(client, params),
|
|
180
181
|
})(tx);
|
|
@@ -192,9 +193,9 @@ export function matchOrders(client, tx, params) {
|
|
|
192
193
|
pool: tx.object(obj.wlpPool),
|
|
193
194
|
senderRequest: req,
|
|
194
195
|
oracle: tx.object(obj.oracle),
|
|
195
|
-
orderTypeTag: params.orderTypeTag,
|
|
196
|
-
triggerPrice: params.triggerPrice,
|
|
197
|
-
maxFills: params.maxFills,
|
|
196
|
+
orderTypeTag: toU8(params.orderTypeTag, "orderTypeTag"),
|
|
197
|
+
triggerPrice: toU128(params.triggerPrice, "triggerPrice"),
|
|
198
|
+
maxFills: toU64(params.maxFills, "maxFills"),
|
|
198
199
|
},
|
|
199
200
|
typeArguments: typeArgs(client, params),
|
|
200
201
|
})(tx);
|
|
@@ -230,8 +231,8 @@ export function openPositionByKeeper(client, tx, params) {
|
|
|
230
231
|
accountObjectAddress: params.accountObjectAddress,
|
|
231
232
|
collateralCoin: params.collateralCoin,
|
|
232
233
|
isLong: params.isLong,
|
|
233
|
-
size: params.size,
|
|
234
|
-
acceptablePrice: params.acceptablePrice,
|
|
234
|
+
size: toU128(params.size, "size"),
|
|
235
|
+
acceptablePrice: toU64(params.acceptablePrice, "acceptablePrice"),
|
|
235
236
|
oracle: tx.object(obj.oracle),
|
|
236
237
|
},
|
|
237
238
|
typeArguments: typeArgs(client, params),
|
|
@@ -249,8 +250,8 @@ export function closePositionByKeeper(client, tx, params) {
|
|
|
249
250
|
ticker: params.ticker,
|
|
250
251
|
pool: tx.object(obj.wlpPool),
|
|
251
252
|
keeperRequest: req,
|
|
252
|
-
positionId: params.positionId,
|
|
253
|
-
acceptablePrice: params.acceptablePrice,
|
|
253
|
+
positionId: toU64(params.positionId, "positionId"),
|
|
254
|
+
acceptablePrice: toU64(params.acceptablePrice, "acceptablePrice"),
|
|
254
255
|
oracle: tx.object(obj.oracle),
|
|
255
256
|
},
|
|
256
257
|
typeArguments: typeArgs(client, params),
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import { makeSenderRequest } from "../../account/account-request.js";
|
|
13
13
|
import * as lp from "../../generated/waterx_perp/lp_pool.js";
|
|
14
|
+
import { toU64 } from "../../utils/validate.js";
|
|
14
15
|
/** Returns the minted `lp_amount` so it can be chained into e.g. `stake`. */
|
|
15
16
|
export function mintWlp(client, tx, params) {
|
|
16
17
|
const req = makeSenderRequest(client, tx, params.bucketAccount);
|
|
@@ -23,8 +24,8 @@ export function mintWlp(client, tx, params) {
|
|
|
23
24
|
aum: tx.object(requireWlpAum(client)),
|
|
24
25
|
senderRequest: req,
|
|
25
26
|
accountId: params.accountId,
|
|
26
|
-
depositAmount: params.depositAmount,
|
|
27
|
-
minLpAmount: params.minLpAmount,
|
|
27
|
+
depositAmount: toU64(params.depositAmount, "depositAmount"),
|
|
28
|
+
minLpAmount: toU64(params.minLpAmount, "minLpAmount"),
|
|
28
29
|
oracle: tx.object(client.config.packages.waterx_oracle.oracle),
|
|
29
30
|
},
|
|
30
31
|
typeArguments: [params.lpType ?? client.wlpType(), params.depositTokenType],
|
|
@@ -48,7 +49,7 @@ export function requestRedeemWlp(client, tx, params) {
|
|
|
48
49
|
wxaRegistry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
49
50
|
senderRequest: req,
|
|
50
51
|
accountId: params.accountId,
|
|
51
|
-
lpAmount: params.lpAmount,
|
|
52
|
+
lpAmount: toU64(params.lpAmount, "lpAmount"),
|
|
52
53
|
},
|
|
53
54
|
typeArguments: [params.lpType ?? client.wlpType(), params.redeemTokenType],
|
|
54
55
|
})(tx);
|
|
@@ -62,7 +63,7 @@ export function cancelRedeemWlp(client, tx, params) {
|
|
|
62
63
|
globalConfig: tx.object(client.config.packages.waterx_perp.global_config),
|
|
63
64
|
wxaRegistry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
64
65
|
senderRequest: req,
|
|
65
|
-
requestId: params.requestId,
|
|
66
|
+
requestId: toU64(params.requestId, "requestId"),
|
|
66
67
|
},
|
|
67
68
|
typeArguments: [params.lpType ?? client.wlpType()],
|
|
68
69
|
})(tx);
|
|
@@ -77,7 +78,7 @@ export function settleRedeemWlp(client, tx, params) {
|
|
|
77
78
|
wxaRegistry: tx.object(client.config.packages.waterx_account.account_registry),
|
|
78
79
|
operatorRequest: req,
|
|
79
80
|
aum: tx.object(requireWlpAum(client)),
|
|
80
|
-
requestId: params.requestId,
|
|
81
|
+
requestId: toU64(params.requestId, "requestId"),
|
|
81
82
|
oracle: tx.object(client.config.packages.waterx_oracle.oracle),
|
|
82
83
|
},
|
|
83
84
|
typeArguments: [params.lpType ?? client.wlpType(), params.redeemTokenType],
|
|
@@ -10,8 +10,17 @@ export declare function resolveSettlementCoinType(client: PredictClient, coinTyp
|
|
|
10
10
|
export declare function resolveMarketRegistry(client: PredictClient, marketRegistry?: string): string;
|
|
11
11
|
export declare function resolveAccountRegistry(client: PredictClient, accountRegistry?: string): string;
|
|
12
12
|
export declare function resolveGlobalConfig(client: PredictClient, globalConfig?: string): string;
|
|
13
|
-
/**
|
|
14
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Ensures `value` is a valid unsigned 64-bit integer.
|
|
15
|
+
*
|
|
16
|
+
* Thin alias for the shared `utils/validate.toU64` — the u64 domain rule
|
|
17
|
+
* (bigint range check; a `number` must be a NON-NEGATIVE SAFE integer, since
|
|
18
|
+
* `2^53 + 2` passes `isInteger` yet has already lost f64 precision and would
|
|
19
|
+
* BCS-encode a silently-wrong value) is authored ONCE there for both product
|
|
20
|
+
* lines. Throws `RangeError` (a subclass of `Error`) naming the parameter.
|
|
21
|
+
*/
|
|
22
|
+
export declare function assertU64(value: bigint | number, name?: string): bigint;
|
|
23
|
+
/** Normalize a u64-ish input (bigint / number / decimal string) to a checked `bigint`. */
|
|
15
24
|
export declare function toBigInt(value: bigint | number | string): bigint;
|
|
16
25
|
export declare function objectArg(tx: Transaction, value: ObjectArgument): TransactionArgument;
|
|
17
26
|
export declare function idArg(tx: Transaction, value: IdArgument): TransactionArgument;
|