@waterx/sdk 2.1.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -169
- package/dist/src/client.d.ts +40 -2
- package/dist/src/client.js +55 -6
- package/dist/src/config.d.ts +66 -3
- package/dist/src/config.js +10 -4
- package/dist/src/constants.d.ts +6 -0
- package/dist/src/constants.js +6 -0
- package/dist/src/core/waterx-account.d.ts +31 -0
- package/dist/src/core/waterx-account.js +26 -0
- package/dist/src/fetch.d.ts +110 -0
- package/dist/src/fetch.js +149 -4
- package/dist/src/generated/bucket_v2_framework/account.d.ts +5 -5
- package/dist/src/generated/bucket_v2_framework/double.d.ts +77 -77
- package/dist/src/generated/bucket_v2_framework/float.d.ts +73 -73
- package/dist/src/generated/bucket_v2_framework/liability.d.ts +33 -33
- package/dist/src/generated/bucket_v2_framework/linked_table.d.ts +5 -5
- package/dist/src/generated/bucket_v2_framework/linked_table.js +2 -2
- package/dist/src/generated/bucket_v2_framework/sheet.d.ts +57 -57
- package/dist/src/generated/bucket_v2_framework/sheet.js +5 -11
- package/dist/src/generated/native_custody/custody_vault.d.ts +46 -32
- package/dist/src/generated/native_custody/custody_vault.js +19 -10
- package/dist/src/generated/native_custody/deps/bucket_v2_framework/sheet.js +1 -3
- package/dist/src/generated/native_custody/events.js +1 -2
- package/dist/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.d.ts +7 -7
- package/dist/src/generated/pyth_sponsor_rule/pyth_sponsor_rule.js +1 -2
- package/dist/src/generated/utils/index.d.ts +7 -7
- package/dist/src/generated/utils/index.js +9 -6
- package/dist/src/generated/waterx_account/account.d.ts +124 -71
- package/dist/src/generated/waterx_account/account.js +64 -29
- package/dist/src/generated/waterx_account/deps/bucket_v2_framework/sheet.js +1 -3
- package/dist/src/generated/waterx_account/direct_rule.d.ts +5 -5
- package/dist/src/generated/waterx_account/events.d.ts +10 -0
- package/dist/src/generated/waterx_account/events.js +31 -50
- package/dist/src/generated/waterx_constant_rule/constant_rule.d.ts +68 -0
- package/dist/src/generated/waterx_constant_rule/constant_rule.js +59 -0
- package/dist/src/generated/waterx_constant_rule/deps/bucket_v2_framework/float.d.ts +8 -0
- package/dist/src/generated/waterx_constant_rule/deps/bucket_v2_framework/float.js +10 -0
- package/dist/src/generated/waterx_constant_rule/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/waterx_constant_rule/deps/sui/vec_map.js +27 -0
- package/dist/src/generated/waterx_credit/credit_registry.d.ts +9 -9
- package/dist/src/generated/waterx_credit/credit_registry.js +1 -2
- package/dist/src/generated/waterx_credit/limited_supply.d.ts +17 -17
- package/dist/src/generated/waterx_oracle/aggregator.js +1 -2
- package/dist/src/generated/waterx_oracle/collector.d.ts +17 -17
- package/dist/src/generated/waterx_oracle/collector.js +1 -1
- package/dist/src/generated/waterx_oracle/oracle.d.ts +5 -5
- package/dist/src/generated/waterx_perp/account_data.d.ts +5 -5
- package/dist/src/generated/waterx_perp/account_data.js +1 -2
- package/dist/src/generated/waterx_perp/deps/bucket_v2_framework/sheet.js +1 -3
- package/dist/src/generated/waterx_perp/events.d.ts +181 -181
- package/dist/src/generated/waterx_perp/events.js +87 -173
- package/dist/src/generated/waterx_perp/global_config.d.ts +3 -3
- package/dist/src/generated/waterx_perp/global_config.js +6 -12
- package/dist/src/generated/waterx_perp/keyed_big_vector.d.ts +9 -9
- package/dist/src/generated/waterx_perp/keyed_big_vector.js +1 -2
- package/dist/src/generated/waterx_perp/lp_pool.d.ts +115 -115
- package/dist/src/generated/waterx_perp/lp_pool.js +11 -22
- package/dist/src/generated/waterx_perp/market_config.d.ts +61 -43
- package/dist/src/generated/waterx_perp/market_config.js +29 -22
- package/dist/src/generated/waterx_perp/math.d.ts +7 -7
- package/dist/src/generated/waterx_perp/order_book.d.ts +47 -47
- package/dist/src/generated/waterx_perp/position.d.ts +99 -99
- package/dist/src/generated/waterx_perp/position.js +6 -12
- package/dist/src/generated/waterx_perp/request.d.ts +67 -67
- package/dist/src/generated/waterx_perp/request.js +2 -3
- package/dist/src/generated/waterx_perp/response.d.ts +35 -35
- package/dist/src/generated/waterx_perp/response.js +1 -2
- package/dist/src/generated/waterx_perp/trading.d.ts +303 -179
- package/dist/src/generated/waterx_perp/trading.js +99 -14
- package/dist/src/generated/waterx_perp_view/view.js +5 -10
- package/dist/src/generated/waterx_pyth_rule/pyth_rule.d.ts +5 -5
- package/dist/src/generated/waterx_pyth_rule/pyth_rule.js +1 -2
- package/dist/src/generated/waterx_referral/referral_table.d.ts +5 -5
- package/dist/src/generated/waterx_referral/referral_table.js +1 -2
- package/dist/src/generated/waterx_staking/waterx_staking.d.ts +19 -19
- package/dist/src/generated/waterx_staking/waterx_staking.js +10 -20
- package/dist/src/generated/waterx_supra_rule/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/waterx_supra_rule/deps/sui/vec_map.js +27 -0
- package/dist/src/generated/waterx_supra_rule/supra_rule.d.ts +158 -0
- package/dist/src/generated/waterx_supra_rule/supra_rule.js +148 -0
- package/dist/src/generated/withdrawal_queue/deps/bucket_v2_framework/float.d.ts +8 -0
- package/dist/src/generated/withdrawal_queue/deps/bucket_v2_framework/float.js +10 -0
- package/dist/src/generated/withdrawal_queue/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/generated/withdrawal_queue/deps/sui/vec_map.js +27 -0
- package/dist/src/generated/withdrawal_queue/withdrawal_queue.d.ts +444 -4
- package/dist/src/generated/withdrawal_queue/withdrawal_queue.js +417 -4
- package/dist/src/generated/wormhole_bridge/wormhole_bridge.d.ts +214 -74
- package/dist/src/generated/wormhole_bridge/wormhole_bridge.js +158 -29
- package/dist/src/index.d.ts +4 -3
- package/dist/src/index.js +3 -2
- package/dist/src/prediction/account.d.ts +96 -0
- package/dist/src/prediction/account.js +230 -0
- package/dist/src/prediction/admin.d.ts +47 -0
- package/dist/src/prediction/admin.js +105 -0
- package/dist/src/prediction/bcs.d.ts +22 -0
- package/dist/src/prediction/bcs.js +240 -0
- package/dist/src/prediction/client.d.ts +75 -0
- package/dist/src/prediction/client.js +164 -0
- package/dist/src/prediction/config.d.ts +60 -0
- package/dist/src/prediction/config.js +75 -0
- package/dist/src/prediction/constants.d.ts +44 -0
- package/dist/src/prediction/constants.js +46 -0
- package/dist/src/prediction/fetch.d.ts +82 -0
- package/dist/src/prediction/fetch.js +270 -0
- package/dist/src/prediction/generated/bucket_v2_framework/account.d.ts +100 -0
- package/dist/src/prediction/generated/bucket_v2_framework/account.js +129 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/std/type_name.d.ts +6 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/std/type_name.js +19 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/balance.d.ts +10 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/balance.js +14 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_map.js +27 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_set.d.ts +16 -0
- package/dist/src/prediction/generated/bucket_v2_framework/deps/sui/vec_set.js +19 -0
- package/dist/src/prediction/generated/bucket_v2_framework/double.d.ts +382 -0
- package/dist/src/prediction/generated/bucket_v2_framework/double.js +466 -0
- package/dist/src/prediction/generated/bucket_v2_framework/float.d.ts +362 -0
- package/dist/src/prediction/generated/bucket_v2_framework/float.js +440 -0
- package/dist/src/prediction/generated/bucket_v2_framework/liability.d.ts +193 -0
- package/dist/src/prediction/generated/bucket_v2_framework/liability.js +205 -0
- package/dist/src/prediction/generated/bucket_v2_framework/linked_table.d.ts +384 -0
- package/dist/src/prediction/generated/bucket_v2_framework/linked_table.js +382 -0
- package/dist/src/prediction/generated/bucket_v2_framework/sheet.d.ts +344 -0
- package/dist/src/prediction/generated/bucket_v2_framework/sheet.js +338 -0
- package/dist/src/prediction/generated/utils/index.d.ts +30 -0
- package/dist/src/prediction/generated/utils/index.js +160 -0
- package/dist/src/prediction/generated/waterx_account/account.d.ts +1589 -0
- package/dist/src/prediction/generated/waterx_account/account.js +1758 -0
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/liability.d.ts +7 -0
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/liability.js +13 -0
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/sheet.d.ts +7 -0
- package/dist/src/prediction/generated/waterx_account/deps/bucket_v2_framework/sheet.js +16 -0
- package/dist/src/prediction/generated/waterx_account/deps/std/type_name.d.ts +6 -0
- package/dist/src/prediction/generated/waterx_account/deps/std/type_name.js +19 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/balance.d.ts +10 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/balance.js +14 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/object_table.d.ts +12 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/object_table.js +19 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/table.d.ts +24 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/table.js +31 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_map.d.ts +36 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_map.js +27 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_set.d.ts +16 -0
- package/dist/src/prediction/generated/waterx_account/deps/sui/vec_set.js +19 -0
- package/dist/src/prediction/generated/waterx_account/direct_rule.d.ts +75 -0
- package/dist/src/prediction/generated/waterx_account/direct_rule.js +78 -0
- package/dist/src/prediction/generated/waterx_account/events.d.ts +33 -0
- package/dist/src/prediction/generated/waterx_account/events.js +137 -0
- package/dist/src/prediction/generated/waterx_account/version.d.ts +10 -0
- package/dist/src/prediction/generated/waterx_account/version.js +8 -0
- package/dist/src/prediction/generated/waterx_prediction/account_data.d.ts +327 -0
- package/dist/src/prediction/generated/waterx_prediction/account_data.js +405 -0
- package/dist/src/prediction/generated/waterx_prediction/admin.d.ts +5 -0
- package/dist/src/prediction/generated/waterx_prediction/admin.js +9 -0
- package/dist/src/prediction/generated/waterx_prediction/bet_sharing.d.ts +60 -0
- package/dist/src/prediction/generated/waterx_prediction/bet_sharing.js +83 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/bucket_v2_framework/linked_table.d.ts +8 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/bucket_v2_framework/linked_table.js +18 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/balance.d.ts +10 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/balance.js +14 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/table.d.ts +24 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/table.js +31 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/vec_set.d.ts +16 -0
- package/dist/src/prediction/generated/waterx_prediction/deps/sui/vec_set.js +19 -0
- package/dist/src/prediction/generated/waterx_prediction/events.d.ts +22 -0
- package/dist/src/prediction/generated/waterx_prediction/events.js +179 -0
- package/dist/src/prediction/generated/waterx_prediction/global_config.d.ts +116 -0
- package/dist/src/prediction/generated/waterx_prediction/global_config.js +141 -0
- package/dist/src/prediction/generated/waterx_prediction/order.d.ts +200 -0
- package/dist/src/prediction/generated/waterx_prediction/order.js +284 -0
- package/dist/src/prediction/generated/waterx_prediction/outcome.d.ts +58 -0
- package/dist/src/prediction/generated/waterx_prediction/outcome.js +73 -0
- package/dist/src/prediction/generated/waterx_prediction/position.d.ts +160 -0
- package/dist/src/prediction/generated/waterx_prediction/position.js +214 -0
- package/dist/src/prediction/generated/waterx_prediction/version.d.ts +10 -0
- package/dist/src/prediction/generated/waterx_prediction/version.js +8 -0
- package/dist/src/prediction/generated/waterx_prediction/view.d.ts +353 -0
- package/dist/src/prediction/generated/waterx_prediction/view.js +432 -0
- package/dist/src/prediction/generated/waterx_prediction/waterx_prediction.d.ts +1698 -0
- package/dist/src/prediction/generated/waterx_prediction/waterx_prediction.js +1733 -0
- package/dist/src/prediction/gift-link.d.ts +6 -0
- package/dist/src/prediction/gift-link.js +5 -0
- package/dist/src/prediction/gift.d.ts +223 -0
- package/dist/src/prediction/gift.js +451 -0
- package/dist/src/prediction/index.d.ts +29 -0
- package/dist/src/prediction/index.js +21 -0
- package/dist/src/prediction/prediction.d.ts +104 -0
- package/dist/src/prediction/prediction.js +317 -0
- package/dist/src/prediction/tx-builders.d.ts +44 -0
- package/dist/src/prediction/tx-builders.js +52 -0
- package/dist/src/prediction/types.d.ts +93 -0
- package/dist/src/prediction/types.js +1 -0
- package/dist/src/prediction/user/account.d.ts +2 -0
- package/dist/src/prediction/user/account.js +1 -0
- package/dist/src/prediction/user/admin.d.ts +6 -0
- package/dist/src/prediction/user/admin.js +3 -0
- package/dist/src/prediction/user/gift.d.ts +2 -0
- package/dist/src/prediction/user/gift.js +1 -0
- package/dist/src/prediction/user/index.d.ts +5 -0
- package/dist/src/prediction/user/index.js +3 -0
- package/dist/src/prediction/user/keeper.d.ts +2 -0
- package/dist/src/prediction/user/keeper.js +1 -0
- package/dist/src/prediction/user/order.d.ts +2 -0
- package/dist/src/prediction/user/order.js +1 -0
- package/dist/src/prediction/user/position.d.ts +2 -0
- package/dist/src/prediction/user/position.js +1 -0
- package/dist/src/prediction/utils/bcs.d.ts +1 -0
- package/dist/src/prediction/utils/bcs.js +1 -0
- package/dist/src/prediction/utils/index.d.ts +1 -0
- package/dist/src/prediction/utils/index.js +1 -0
- package/dist/src/prediction/utils.d.ts +30 -0
- package/dist/src/prediction/utils.js +177 -0
- package/dist/src/sdk.d.ts +18 -0
- package/dist/src/sdk.js +17 -0
- package/dist/src/tx-builders.d.ts +54 -0
- package/dist/src/tx-builders.js +141 -0
- package/dist/src/unified-client.d.ts +407 -0
- package/dist/src/unified-client.js +123 -0
- package/dist/src/user/account.d.ts +27 -0
- package/dist/src/user/account.js +34 -8
- package/dist/src/user/credit.d.ts +8 -14
- package/dist/src/user/credit.js +9 -23
- package/dist/src/user/custody.d.ts +4 -18
- package/dist/src/user/custody.js +14 -25
- package/dist/src/utils/consolidate-balance.d.ts +37 -0
- package/dist/src/utils/consolidate-balance.js +89 -0
- package/dist/src/utils/math.d.ts +86 -0
- package/dist/src/utils/math.js +100 -0
- package/dist/src/utils/pyth.d.ts +42 -7
- package/dist/src/utils/pyth.js +107 -31
- package/package.json +129 -34
package/dist/src/utils/pyth.js
CHANGED
|
@@ -19,8 +19,10 @@ import { bcs } from "@mysten/sui/bcs";
|
|
|
19
19
|
// the market's `request_checklist` contains `PythSponsorRule`.
|
|
20
20
|
// ============================================================================
|
|
21
21
|
import { reimburse as sponsorReimburse, request as sponsorRequest, } from "../generated/pyth_sponsor_rule/pyth_sponsor_rule.js";
|
|
22
|
+
import { feed as constantRuleFeed } from "../generated/waterx_constant_rule/constant_rule.js";
|
|
22
23
|
import { aggregate as aggregateCall, newCollector } from "../generated/waterx_oracle/oracle.js";
|
|
23
24
|
import { feed as pythRuleFeed } from "../generated/waterx_pyth_rule/pyth_rule.js";
|
|
25
|
+
import { feed as supraRuleFeed } from "../generated/waterx_supra_rule/supra_rule.js";
|
|
24
26
|
export class PythCache {
|
|
25
27
|
pythStateInfo;
|
|
26
28
|
wormholePackageId;
|
|
@@ -226,54 +228,128 @@ export async function updatePythPrices(tx, client, feedIds, cache, sponsorFund)
|
|
|
226
228
|
// Per-ticker refresh: collector → pyth_rule::feed → oracle::aggregate
|
|
227
229
|
// ============================================================================
|
|
228
230
|
/**
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
+
* Aggregate one ticker's price into the shared `Oracle`: build a collector, feed
|
|
232
|
+
* every rule the ticker is configured for, then `aggregate`. The fed rule set must
|
|
233
|
+
* match the on-chain weighted set for the ticker — `aggregator::remove_outliers`
|
|
234
|
+
* aborts `EMissingPriceSource` if a weighted rule is missing from the collector:
|
|
231
235
|
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
236
|
+
* - **Pyth** — fed when `priceInfoObjectId` is supplied (i.e. the ticker has a
|
|
237
|
+
* `pyth_rule.feeds` entry). Caller must run the Pyth update first so the
|
|
238
|
+
* `PriceInfoObject` is fresh.
|
|
239
|
+
* - **Supra** — fed alongside Pyth when supra is enabled + wired (abstains on-chain
|
|
240
|
+
* for symbols it has no pair for).
|
|
241
|
+
* - **Constant** — fed when the ticker is a constant ticker
|
|
242
|
+
* ({@link WaterXClient.isConstantTicker}).
|
|
243
|
+
*
|
|
244
|
+
* "Dual-feed" (Pyth + Constant) and "constant-only" are not special cases — they
|
|
245
|
+
* fall out of which rules the ticker is in: a constant ticker that also has a Pyth
|
|
246
|
+
* feed gets both; one with no Pyth feed (no `priceInfoObjectId`) gets constant only.
|
|
247
|
+
* Throws if no rule applies to the ticker.
|
|
234
248
|
*/
|
|
235
|
-
export function
|
|
249
|
+
export function aggregateTicker(tx, client, args) {
|
|
250
|
+
const oraclePkg = client.config.packages.waterx_oracle.published_at;
|
|
236
251
|
const collector = newCollector({
|
|
237
|
-
package:
|
|
252
|
+
package: oraclePkg,
|
|
238
253
|
arguments: { symbol: args.ticker },
|
|
239
254
|
})(tx);
|
|
240
|
-
|
|
241
|
-
|
|
255
|
+
let fed = false;
|
|
256
|
+
if (args.priceInfoObjectId) {
|
|
257
|
+
pythRuleFeed({
|
|
258
|
+
package: client.config.packages.pyth_rule.published_at,
|
|
259
|
+
arguments: {
|
|
260
|
+
collector,
|
|
261
|
+
config: tx.object(client.config.packages.pyth_rule.config),
|
|
262
|
+
pythState: tx.object(client.pyth.state_id),
|
|
263
|
+
pythPriceInfo: tx.object(args.priceInfoObjectId),
|
|
264
|
+
},
|
|
265
|
+
})(tx);
|
|
266
|
+
// Supra rides on the same collector when enabled (abstains on-chain otherwise).
|
|
267
|
+
maybeFeedSupra(tx, client, collector);
|
|
268
|
+
fed = true;
|
|
269
|
+
}
|
|
270
|
+
if (client.isConstantTicker(args.ticker)) {
|
|
271
|
+
const constant = client.config.packages.constant_rule;
|
|
272
|
+
constantRuleFeed({
|
|
273
|
+
package: constant.published_at,
|
|
274
|
+
arguments: { collector, config: tx.object(constant.config) },
|
|
275
|
+
})(tx);
|
|
276
|
+
fed = true;
|
|
277
|
+
}
|
|
278
|
+
if (!fed) {
|
|
279
|
+
throw new Error(`no oracle rule configured for ticker '${args.ticker}' (no pyth feed, not a constant ticker)`);
|
|
280
|
+
}
|
|
281
|
+
aggregateCall({
|
|
282
|
+
package: oraclePkg,
|
|
242
283
|
arguments: {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
pythState: tx.object(client.pyth.state_id),
|
|
246
|
-
pythPriceInfo: tx.object(args.priceInfoObjectId),
|
|
284
|
+
oracle: tx.object(client.config.packages.waterx_oracle.oracle),
|
|
285
|
+
collector,
|
|
247
286
|
},
|
|
248
287
|
})(tx);
|
|
249
|
-
|
|
250
|
-
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* Thin wrapper over {@link aggregateTicker} for a Pyth-fed ticker. Kept for
|
|
291
|
+
* back-compat (e.g. WLP mint builds). Caller must run the Pyth update first.
|
|
292
|
+
*/
|
|
293
|
+
export function aggregateTickerWithPyth(tx, client, args) {
|
|
294
|
+
aggregateTicker(tx, client, args);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Append a `supra_rule::feed` on `collector` when the deployment has supra
|
|
298
|
+
* enabled + wired (see {@link WaterXClient.getSupraRule}). No-op otherwise, so
|
|
299
|
+
* Pyth-only deployments are unchanged.
|
|
300
|
+
*/
|
|
301
|
+
function maybeFeedSupra(tx, client, collector) {
|
|
302
|
+
const supra = client.getSupraRule();
|
|
303
|
+
if (!supra)
|
|
304
|
+
return;
|
|
305
|
+
supraRuleFeed({
|
|
306
|
+
package: supra.published_at,
|
|
251
307
|
arguments: {
|
|
252
|
-
|
|
253
|
-
|
|
308
|
+
collector,
|
|
309
|
+
config: tx.object(supra.config),
|
|
310
|
+
oracleHolder: tx.object(supra.oracle_holder),
|
|
254
311
|
},
|
|
255
312
|
})(tx);
|
|
256
313
|
}
|
|
257
314
|
/**
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
315
|
+
* {@link aggregateTicker} for a **constant-only** ticker (no Pyth update needed —
|
|
316
|
+
* the price comes from the on-chain `constant_rule::Config`).
|
|
317
|
+
*
|
|
318
|
+
* Throws if the ticker ALSO has a `pyth_rule.feeds` entry (a dual-feed transition
|
|
319
|
+
* ticker): feeding only the constant leg would leave the still-weighted Pyth rule
|
|
320
|
+
* absent from the collector and abort `aggregate` with `EMissingPriceSource`. Such
|
|
321
|
+
* tickers must go through {@link aggregateTicker} with a `priceInfoObjectId` (or
|
|
322
|
+
* {@link refreshOraclePrices}), which feeds both.
|
|
323
|
+
*/
|
|
324
|
+
export function aggregateTickerWithConstant(tx, client, args) {
|
|
325
|
+
if (client.config.packages.pyth_rule?.feeds?.[args.ticker] !== undefined) {
|
|
326
|
+
throw new Error(`'${args.ticker}' is in pyth_rule.feeds (dual-feed) — feed both via aggregateTicker({ priceInfoObjectId }) / refreshOraclePrices, not aggregateTickerWithConstant`);
|
|
327
|
+
}
|
|
328
|
+
aggregateTicker(tx, client, { ticker: args.ticker });
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Refresh multiple tickers in one PTB. For each ticker {@link aggregateTicker}
|
|
332
|
+
* feeds whichever rules it is configured for (Pyth if it has a `pyth_rule.feeds`
|
|
333
|
+
* entry, Supra when enabled, Constant when it's a constant ticker). Tickers with a
|
|
334
|
+
* Pyth feed are updated on-chain via one shared Pyth accumulator first; the rest
|
|
335
|
+
* (constant-only) skip Pyth entirely.
|
|
261
336
|
*/
|
|
262
337
|
export async function refreshOraclePrices(tx, client, tickers, opts = {}) {
|
|
263
338
|
if (tickers.length === 0)
|
|
264
339
|
return;
|
|
265
|
-
//
|
|
266
|
-
//
|
|
267
|
-
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
340
|
+
// Every ticker with a pyth_rule.feeds entry needs the on-chain Pyth update
|
|
341
|
+
// first (one shared accumulator). Constant-only tickers (no pyth feed) skip it.
|
|
342
|
+
const pythTickers = tickers.filter((t) => client.config.packages.pyth_rule?.feeds?.[t] !== undefined);
|
|
343
|
+
const priceInfoByTicker = new Map();
|
|
344
|
+
if (pythTickers.length > 0) {
|
|
345
|
+
const entries = pythTickers.map((t) => client.getPythFeed(t));
|
|
346
|
+
await updatePythPrices(tx, client, entries.map((e) => e.feed_id), opts.cache, opts.sponsorFund);
|
|
347
|
+
pythTickers.forEach((t, i) => priceInfoByTicker.set(t, entries[i].price_info_object));
|
|
348
|
+
}
|
|
349
|
+
// Aggregate each ticker, feeding whichever rules it is configured for.
|
|
350
|
+
for (const ticker of tickers) {
|
|
351
|
+
aggregateTicker(tx, client, { ticker, priceInfoObjectId: priceInfoByTicker.get(ticker) });
|
|
352
|
+
}
|
|
277
353
|
}
|
|
278
354
|
/**
|
|
279
355
|
* Opens a `Fund` hot potato from the shared PythSponsor pool. Pass the
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@waterx/sdk",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "WaterX
|
|
3
|
+
"version": "2.4.0",
|
|
4
|
+
"description": "WaterX SDK — perpetuals and prediction markets on Sui",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "WaterX",
|
|
7
7
|
"repository": {
|
|
@@ -9,8 +9,51 @@
|
|
|
9
9
|
"url": "https://github.com/WaterXProtocol/waterx-sdk.git"
|
|
10
10
|
},
|
|
11
11
|
"type": "module",
|
|
12
|
-
"main": "dist/src/
|
|
13
|
-
"types": "dist/src/
|
|
12
|
+
"main": "dist/src/sdk.js",
|
|
13
|
+
"types": "dist/src/sdk.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/src/sdk.d.ts",
|
|
17
|
+
"import": "./dist/src/sdk.js"
|
|
18
|
+
},
|
|
19
|
+
"./perp": {
|
|
20
|
+
"types": "./dist/src/index.d.ts",
|
|
21
|
+
"import": "./dist/src/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./perp/*": {
|
|
24
|
+
"types": "./dist/src/*.d.ts",
|
|
25
|
+
"import": "./dist/src/*.js"
|
|
26
|
+
},
|
|
27
|
+
"./prediction": {
|
|
28
|
+
"types": "./dist/src/prediction/index.d.ts",
|
|
29
|
+
"import": "./dist/src/prediction/index.js"
|
|
30
|
+
},
|
|
31
|
+
"./prediction/user": {
|
|
32
|
+
"types": "./dist/src/prediction/user/index.d.ts",
|
|
33
|
+
"import": "./dist/src/prediction/user/index.js"
|
|
34
|
+
},
|
|
35
|
+
"./prediction/user/*": {
|
|
36
|
+
"types": "./dist/src/prediction/user/*.d.ts",
|
|
37
|
+
"import": "./dist/src/prediction/user/*.js"
|
|
38
|
+
},
|
|
39
|
+
"./prediction/utils": {
|
|
40
|
+
"types": "./dist/src/prediction/utils/index.d.ts",
|
|
41
|
+
"import": "./dist/src/prediction/utils/index.js"
|
|
42
|
+
},
|
|
43
|
+
"./prediction/utils/*": {
|
|
44
|
+
"types": "./dist/src/prediction/utils/*.d.ts",
|
|
45
|
+
"import": "./dist/src/prediction/utils/*.js"
|
|
46
|
+
},
|
|
47
|
+
"./prediction/*": {
|
|
48
|
+
"types": "./dist/src/prediction/*.d.ts",
|
|
49
|
+
"import": "./dist/src/prediction/*.js"
|
|
50
|
+
},
|
|
51
|
+
"./generated/*": {
|
|
52
|
+
"types": "./dist/src/generated/*.d.ts",
|
|
53
|
+
"import": "./dist/src/generated/*.js"
|
|
54
|
+
},
|
|
55
|
+
"./package.json": "./package.json"
|
|
56
|
+
},
|
|
14
57
|
"files": [
|
|
15
58
|
"dist",
|
|
16
59
|
"LICENSE",
|
|
@@ -21,46 +64,98 @@
|
|
|
21
64
|
"codegen": "tsx scripts/codegen-summaries.ts && npx sui-ts-codegen generate && tsx scripts/fix-generated-imports.ts",
|
|
22
65
|
"lint": "pnpm lint:eslint && pnpm lint:prettier",
|
|
23
66
|
"lint:eslint": "eslint \"src/**/*.ts\" \"test/**/*.ts\" \"scripts/**/*.ts\" \"examples/**/*.ts\" \"vitest.config.ts\"",
|
|
24
|
-
"lint:prettier": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\" \"scripts/**/*.ts\" \"examples/**/*.ts\" \"vitest.config.ts\" \"eslint.config.mjs\" \"sui-codegen.config.mjs\"",
|
|
67
|
+
"lint:prettier": "prettier --check \"src/**/*.ts\" \"test/**/*.ts\" \"scripts/**/*.ts\" \"examples/**/*.ts\" \"vitest.config.ts\" \"eslint.config.mjs\" \"sui-codegen.config.mjs\" \"packages/predict-stress/**/*.{ts,mjs,json,md}\"",
|
|
25
68
|
"lint:fix": "eslint \"src/**/*.ts\" \"test/**/*.ts\" \"scripts/**/*.ts\" \"examples/**/*.ts\" \"vitest.config.ts\" --fix",
|
|
26
|
-
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"scripts/**/*.ts\" \"examples/**/*.ts\" \"vitest.config.ts\" \"eslint.config.mjs\" \"sui-codegen.config.mjs\"",
|
|
69
|
+
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"scripts/**/*.ts\" \"examples/**/*.ts\" \"vitest.config.ts\" \"eslint.config.mjs\" \"sui-codegen.config.mjs\" \"packages/predict-stress/**/*.{ts,mjs,json,md}\"",
|
|
27
70
|
"env:init": "tsx scripts/init-local-env.ts",
|
|
28
71
|
"typecheck": "tsc --noEmit",
|
|
29
|
-
"
|
|
30
|
-
"test
|
|
31
|
-
"test:
|
|
32
|
-
"test:
|
|
33
|
-
"test:
|
|
34
|
-
"test:
|
|
35
|
-
"test:
|
|
72
|
+
"check": "pnpm lint && pnpm typecheck && pnpm test:unit",
|
|
73
|
+
"test": "vitest run --project unit --project predict-unit",
|
|
74
|
+
"test:unit": "vitest run --project unit --project predict-unit",
|
|
75
|
+
"test:unit:perp": "vitest run --project unit",
|
|
76
|
+
"test:unit:predict": "vitest run --project predict-unit",
|
|
77
|
+
"test:post-build": "vitest run --project post-build",
|
|
78
|
+
"test:e2e": "tsx scripts/run-e2e.ts --testnet --predict",
|
|
79
|
+
"test:e2e:perp": "tsx scripts/run-e2e.ts --testnet",
|
|
80
|
+
"test:e2e:predict": "tsx scripts/run-e2e.ts --testnet --predict-only",
|
|
81
|
+
"test:e2e:testnet": "tsx scripts/run-e2e.ts --testnet --predict",
|
|
82
|
+
"test:e2e:mainnet": "tsx scripts/run-e2e.ts --mainnet --predict",
|
|
83
|
+
"test:integration": "pnpm test:integration:perp && pnpm test:integration:predict",
|
|
84
|
+
"test:integration:perp": "tsx scripts/run-integration.ts --testnet",
|
|
85
|
+
"test:integration:predict": "vitest run --project predict-integration",
|
|
86
|
+
"test:integration:predict:keeper": "vitest run --project predict-integration-keeper",
|
|
87
|
+
"test:integration:predict:admin": "vitest run --project predict-integration-admin",
|
|
88
|
+
"test:integration:predict:all": "vitest run --project predict-integration --project predict-integration-keeper --project predict-integration-admin",
|
|
89
|
+
"test:api": "node test/prediction/scripts/run-api-tests.mjs",
|
|
90
|
+
"test:api:local": "node test/prediction/scripts/run-api-tests.mjs --env local",
|
|
91
|
+
"test:api:staging": "node test/prediction/scripts/run-api-tests.mjs --env staging",
|
|
92
|
+
"test:integration:predict:crosscheck": "E2E_API_ENV=staging E2E_API_CROSSCHECK=1 vitest run --project predict-integration-crosscheck",
|
|
93
|
+
"test:integration:predict:settlement-crosscheck": "E2E_API_ENV=staging E2E_SETTLEMENT_CROSSCHECK=1 vitest run --project predict-integration-settlement-crosscheck",
|
|
94
|
+
"test:integration:predict:headless": "E2E_API_ENV=staging E2E_HEADLESS_BET=1 vitest run --project predict-integration-headless",
|
|
95
|
+
"test:integration:predict:journey": "vitest run --project predict-integration test/prediction/integration/user-betting-journey.test.ts",
|
|
96
|
+
"test:integration:perp:mainnet": "tsx scripts/run-integration.ts --mainnet",
|
|
97
|
+
"test:integration:perp:lifecycle": "tsx scripts/run-integration.ts --testnet test/perp/integration/user/trader-position-lifecycle.test.ts",
|
|
98
|
+
"test:integration:perp:market-config": "tsx scripts/run-integration.ts --testnet test/perp/integration/user/trader-market-onchain-config.test.ts",
|
|
99
|
+
"test:integration:perp:persistent-state": "tsx scripts/run-integration.ts --testnet test/perp/integration/user/trader-e2e-persistent-state.test.ts",
|
|
100
|
+
"test:integration:perp:gap": "tsx scripts/run-integration.ts --testnet test/perp/integration/user/trader-wlp-redeem.test.ts test/perp/integration/user/trader-staking.test.ts test/perp/integration/user/trader-keeper-roundtrip.test.ts test/perp/integration/user/trader-custody.test.ts test/perp/integration/user/trader-credit-pipeline.test.ts",
|
|
101
|
+
"test:integration:perp:onboarding": "tsx scripts/run-integration.ts --testnet test/perp/integration/user/trader-full-onboarding.test.ts",
|
|
36
102
|
"smoke:chain": "tsx scripts/run-smoke-chain.ts",
|
|
37
|
-
"smoke:chain:dry": "tsx scripts/run-smoke-chain.ts --dry-run"
|
|
103
|
+
"smoke:chain:dry": "tsx scripts/run-smoke-chain.ts --dry-run",
|
|
104
|
+
"seed:testnet": "tsx test/prediction/scripts/seed-testnet.ts",
|
|
105
|
+
"predict:list-accounts": "tsx test/prediction/scripts/list-accounts.ts",
|
|
106
|
+
"predict:bootstrap-stress-accounts": "tsx test/prediction/scripts/bootstrap-stress-accounts.ts",
|
|
107
|
+
"predict:bootstrap-stress-deposits": "tsx test/prediction/scripts/bootstrap-stress-deposits.ts",
|
|
108
|
+
"mint:api-jwt": "node test/prediction/scripts/mint-api-jwt.mjs",
|
|
109
|
+
"mint:api-jwt:staging": "node test/prediction/scripts/fetch-staging-api-jwt.mjs",
|
|
110
|
+
"diagnose:bets-api": "tsx test/prediction/scripts/diagnose-bets-chain-api.ts",
|
|
111
|
+
"predict:scan-claimable": "E2E_API_ENV=staging tsx test/prediction/scripts/scan-claimable-crosscheck.ts",
|
|
112
|
+
"predict:place-all-markets": "E2E_API_ENV=staging tsx test/prediction/scripts/place-all-catalog-markets.ts",
|
|
113
|
+
"predict:place-dry-run": "E2E_API_ENV=staging E2E_PLACE_ALL_DRY_RUN=1 tsx test/prediction/scripts/place-all-catalog-markets.ts",
|
|
114
|
+
"predict:place-broker-only": "E2E_API_ENV=staging E2E_PLACE_ALL_BROKER_ONLY=1 E2E_PLACE_ALL_ONE_SIDE=1 E2E_PLACE_ALL_LIMIT=1 tsx test/prediction/scripts/place-all-catalog-markets.ts",
|
|
115
|
+
"predict:place-and-watch": "E2E_API_ENV=staging E2E_STAGING_BET_USD=1.12 E2E_PLACE_ALL_PLACE_ONLY=1 E2E_PLACE_ALL_ONE_SIDE=1 E2E_PLACE_ALL_LIMIT=1 tsx test/prediction/scripts/place-all-catalog-markets.ts",
|
|
116
|
+
"predict:place-stress": "E2E_API_ENV=staging tsx test/prediction/scripts/place-stress-multi-wallet.ts",
|
|
117
|
+
"predict:place-stress-dry-run": "E2E_API_ENV=staging E2E_STRESS_DRY_RUN=1 tsx test/prediction/scripts/place-stress-multi-wallet.ts",
|
|
118
|
+
"predict:place-stress-smoke": "E2E_API_ENV=staging E2E_STRESS_PHASES=1 E2E_STRESS_PLACE_ONLY=1 E2E_STRESS_COOLDOWN_MS=0 tsx test/prediction/scripts/place-stress-multi-wallet.ts",
|
|
119
|
+
"predict:place-stress-smoke-fill": "E2E_API_ENV=staging E2E_STRESS_PHASES=1 E2E_STRESS_COOLDOWN_MS=0 tsx test/prediction/scripts/place-stress-multi-wallet.ts",
|
|
120
|
+
"predict:place-stress-ramp": "E2E_API_ENV=staging tsx test/prediction/scripts/place-stress-multi-wallet.ts",
|
|
121
|
+
"predict:place-stress-timing": "E2E_API_ENV=staging E2E_STRESS_PHASES=1,2,4,8 E2E_STRESS_COOLDOWN_MS=30000 tsx test/prediction/scripts/place-stress-multi-wallet.ts",
|
|
122
|
+
"predict:place-stress-timing-max": "E2E_API_ENV=staging E2E_STRESS_PHASES=8 E2E_STRESS_COOLDOWN_MS=0 tsx test/prediction/scripts/place-stress-multi-wallet.ts",
|
|
123
|
+
"predict:place-stress-hammer": "E2E_API_ENV=staging E2E_STRESS_HAMMER=1 E2E_STRESS_PLACE_ONLY=1 E2E_STRESS_COOLDOWN_MS=0 E2E_STRESS_ROUNDS=10 tsx test/prediction/scripts/place-stress-multi-wallet.ts",
|
|
124
|
+
"predict:place-stress-hammer-smoke": "E2E_API_ENV=staging E2E_STRESS_HAMMER=1 E2E_STRESS_PLACE_ONLY=1 E2E_STRESS_COOLDOWN_MS=0 E2E_STRESS_ROUNDS=1 tsx test/prediction/scripts/place-stress-multi-wallet.ts",
|
|
125
|
+
"predict-stress": "pnpm --dir packages/predict-stress",
|
|
126
|
+
"predict:refund-probe": "E2E_API_ENV=staging tsx test/prediction/scripts/probe-catalog-refund.ts",
|
|
127
|
+
"predict:broker-matrix": "E2E_API_ENV=staging tsx test/prediction/scripts/probe-broker-matrix.ts",
|
|
128
|
+
"test:integration:predict:refund": "E2E_API_ENV=staging E2E_CATALOG_REFUND=1 vitest run --project predict-integration-refund",
|
|
129
|
+
"test:integration:predict:broker-matrix": "E2E_API_ENV=staging E2E_BROKER_MATRIX=1 vitest run --project predict-integration-broker-matrix"
|
|
130
|
+
},
|
|
131
|
+
"dependencies": {
|
|
132
|
+
"@noble/hashes": "^2.2.0"
|
|
38
133
|
},
|
|
39
134
|
"peerDependencies": {
|
|
40
135
|
"@mysten/bcs": "^1.9.0",
|
|
41
136
|
"@mysten/sui": "^2.9.0"
|
|
42
137
|
},
|
|
43
138
|
"devDependencies": {
|
|
44
|
-
"@eslint/js": "
|
|
45
|
-
"@ianvs/prettier-plugin-sort-imports": "
|
|
46
|
-
"@mysten/bcs": "
|
|
47
|
-
"@mysten/
|
|
48
|
-
"@mysten/
|
|
49
|
-
"@types/node": "
|
|
50
|
-
"@typescript-eslint/eslint-plugin": "
|
|
51
|
-
"@typescript-eslint/parser": "
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"prettier": "
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"vitest": "
|
|
139
|
+
"@eslint/js": "10.0.1",
|
|
140
|
+
"@ianvs/prettier-plugin-sort-imports": "4.7.1",
|
|
141
|
+
"@mysten/bcs": "1.9.2",
|
|
142
|
+
"@mysten/codegen": "0.10.6",
|
|
143
|
+
"@mysten/sui": "2.17.0",
|
|
144
|
+
"@types/node": "25.9.1",
|
|
145
|
+
"@typescript-eslint/eslint-plugin": "8.60.0",
|
|
146
|
+
"@typescript-eslint/parser": "8.60.0",
|
|
147
|
+
"@vitest/coverage-v8": "4.1.8",
|
|
148
|
+
"dotenv": "17.4.2",
|
|
149
|
+
"eslint": "10.4.1",
|
|
150
|
+
"eslint-config-prettier": "10.1.8",
|
|
151
|
+
"globals": "17.6.0",
|
|
152
|
+
"prettier": "3.8.3",
|
|
153
|
+
"tsc-alias": "1.8.17",
|
|
154
|
+
"tsconfig-paths": "4.2.0",
|
|
155
|
+
"tsx": "4.22.4",
|
|
156
|
+
"typescript": "6.0.3",
|
|
157
|
+
"typescript-eslint": "8.60.0",
|
|
158
|
+
"vitest": "4.1.8"
|
|
64
159
|
},
|
|
65
160
|
"packageManager": "pnpm@9.15.0"
|
|
66
161
|
}
|