@waterx/sdk 3.0.3 → 3.1.1

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.
Files changed (36) hide show
  1. package/README.md +17 -7
  2. package/dist/cjs/src/perp/config.d.ts +6 -16
  3. package/dist/cjs/src/perp/config.js +4 -12
  4. package/dist/cjs/src/perp/index.d.ts +1 -1
  5. package/dist/cjs/src/perp/index.js +3 -4
  6. package/dist/cjs/src/prediction/client.d.ts +11 -0
  7. package/dist/cjs/src/prediction/client.js +16 -0
  8. package/dist/cjs/src/prediction/config.d.ts +5 -15
  9. package/dist/cjs/src/prediction/config.js +4 -12
  10. package/dist/cjs/src/prediction/fetch.d.ts +6 -1
  11. package/dist/cjs/src/prediction/fetch.js +64 -0
  12. package/dist/cjs/src/prediction/gift.d.ts +19 -0
  13. package/dist/cjs/src/prediction/gift.js +26 -1
  14. package/dist/cjs/src/prediction/index.d.ts +2 -2
  15. package/dist/cjs/src/prediction/index.js +7 -4
  16. package/dist/cjs/src/prediction/types.d.ts +19 -0
  17. package/dist/cjs/src/unified-client.d.ts +9 -4
  18. package/dist/cjs/src/unified-client.js +2 -2
  19. package/dist/src/perp/config.d.ts +6 -16
  20. package/dist/src/perp/config.js +4 -11
  21. package/dist/src/perp/index.d.ts +1 -1
  22. package/dist/src/perp/index.js +1 -1
  23. package/dist/src/prediction/client.d.ts +11 -0
  24. package/dist/src/prediction/client.js +16 -0
  25. package/dist/src/prediction/config.d.ts +5 -15
  26. package/dist/src/prediction/config.js +4 -11
  27. package/dist/src/prediction/fetch.d.ts +6 -1
  28. package/dist/src/prediction/fetch.js +60 -0
  29. package/dist/src/prediction/gift.d.ts +19 -0
  30. package/dist/src/prediction/gift.js +26 -1
  31. package/dist/src/prediction/index.d.ts +2 -2
  32. package/dist/src/prediction/index.js +2 -2
  33. package/dist/src/prediction/types.d.ts +19 -0
  34. package/dist/src/unified-client.d.ts +9 -4
  35. package/dist/src/unified-client.js +2 -2
  36. package/package.json +1 -1
package/README.md CHANGED
@@ -11,13 +11,18 @@ The perp and prediction lines expose builder functions with **colliding names**
11
11
  ```ts
12
12
  import { WaterXClient } from "@waterx/sdk";
13
13
 
14
- const client = await WaterXClient.create({ network: "TESTNET" });
14
+ // waterxConfigUrl is REQUIRED the SDK has no built-in default and never reads env.
15
+ const client = await WaterXClient.create({
16
+ network: "TESTNET",
17
+ waterxConfigUrl: "https://raw.githubusercontent.com/WaterXProtocol/waterx-config/main/testnet.json",
18
+ });
15
19
  client.account.createAccount(tx, { alias }); // shared waterx_account + funding (credit/custody)
16
20
  client.perp.buildPlaceOrderTx(params); // perpetuals
17
21
  client.predict.placeOrder(tx, params); // prediction markets
18
22
  // client.perp / client.predict ARE the line clients — sign/execute on them directly:
19
23
  // await client.perp.signAndExecuteTransaction({ transaction: tx, signer })
20
- // each line can target a different network: WaterXClient.create({ perp: { network: "MAINNET" }, predict: { network: "TESTNET" } })
24
+ // each line can target a different network + URL:
25
+ // WaterXClient.create({ perp: { network: "MAINNET", waterxConfigUrl: mainnetUrl }, predict: { network: "TESTNET", waterxConfigUrl: testnetUrl } })
21
26
  ```
22
27
 
23
28
  > `WaterXClient` is the umbrella entry point. `Client` is kept as a **deprecated alias** for one major cycle.
@@ -41,13 +46,16 @@ Consumers: `pnpm add @waterx/sdk @mysten/sui`
41
46
 
42
47
  ## Quickstart (unified client)
43
48
 
44
- `WaterXClient.create()` loads each line's deployment config from the canonical `waterx-config` JSON and returns a ready client. Builders are **build-only** — they return / mutate a `Transaction`; signing & execution stay with the caller (`client.perp` / `client.predict` are the line clients, or a frontend wallet), so multi-step Pyth injection and wallet flows keep working.
49
+ `WaterXClient.create()` loads each line's deployment config from the canonical `waterx-config` JSON (its URL passed via the **required** `waterxConfigUrl` option — the SDK has no default and never reads env) and returns a ready client. Builders are **build-only** — they return / mutate a `Transaction`; signing & execution stay with the caller (`client.perp` / `client.predict` are the line clients, or a frontend wallet), so multi-step Pyth injection and wallet flows keep working.
45
50
 
46
51
  ```ts
47
52
  import { WaterXClient, rawPrice } from "@waterx/sdk";
48
53
  import { Transaction } from "@mysten/sui/transactions";
49
54
 
50
- const client = await WaterXClient.create({ network: "TESTNET" });
55
+ const client = await WaterXClient.create({
56
+ network: "TESTNET",
57
+ waterxConfigUrl: "https://raw.githubusercontent.com/WaterXProtocol/waterx-config/main/testnet.json",
58
+ });
51
59
  const signer = /* your Ed25519Keypair or wallet Signer */;
52
60
 
53
61
  // --- Perp: place a market order ---
@@ -77,14 +85,16 @@ await client.predict.signAndExecuteTransaction({ transaction: ptx, signer });
77
85
 
78
86
  ## Per-line clients
79
87
 
80
- If you only need one line, construct it directly (both factories are **async** — they fetch deployment config):
88
+ If you only need one line, construct it directly (both factories are **async** — they fetch deployment config; `waterxConfigUrl` is **required**):
81
89
 
82
90
  ```ts
83
91
  import { PerpClient } from "@waterx/sdk/perp";
84
92
  import { PredictClient } from "@waterx/sdk/prediction";
85
93
 
86
- const perp = await PerpClient.create("TESTNET"); // or PerpClient.testnet()
87
- const predict = await PredictClient.create("TESTNET"); // or PredictClient.testnet()
94
+ const waterxConfigUrl =
95
+ "https://raw.githubusercontent.com/WaterXProtocol/waterx-config/main/testnet.json";
96
+ const perp = await PerpClient.create("TESTNET", { waterxConfigUrl }); // or PerpClient.testnet({ waterxConfigUrl })
97
+ const predict = await PredictClient.create("TESTNET", { waterxConfigUrl }); // or PredictClient.testnet({ waterxConfigUrl })
88
98
  ```
89
99
 
90
100
  Read-only queries use gRPC `simulateTransaction` (no signer) — the `getX` view helpers, e.g. `await perp.simulate(tx)` or `getMarketData(perp, …)`.
@@ -95,18 +95,13 @@ export interface WaterXConfig {
95
95
  }
96
96
  export interface LoadConfigOptions {
97
97
  /**
98
- * Override the default config URL. Use this to point at a staging branch
99
- * (`?ref=staging`) or a local mirror during development. Takes precedence
100
- * over {@link configRef}.
98
+ * Canonical `waterx-config` JSON URL to fetch, **as-is** (no `<network>.json`
99
+ * / git ref appended). Required {@link loadConfig} reads the URL only from
100
+ * this option (there is no env-var fallback and no built-in default) and
101
+ * throws when it is unset. Point it at a staging deployment or local mirror
102
+ * as needed.
101
103
  */
102
- configUrl?: string;
103
- /**
104
- * Pin the canonical config to a specific git ref — a commit SHA, branch,
105
- * or tag — instead of the default `main` branch. Resolves to
106
- * `https://raw.githubusercontent.com/WaterXProtocol/waterx-config/<ref>/<network>.json`.
107
- * Ignored when {@link configUrl} is set.
108
- */
109
- configRef?: string;
104
+ waterxConfigUrl?: string;
110
105
  /**
111
106
  * Reuse a previously-fetched config from the in-memory cache (keyed by
112
107
  * the effective URL). Default: false (always fetch fresh).
@@ -117,10 +112,5 @@ export interface LoadConfigOptions {
117
112
  /** Optional request timeout in ms. Default 10_000. */
118
113
  timeoutMs?: number;
119
114
  }
120
- /**
121
- * Build the canonical config URL for `network`, optionally pinned to a
122
- * specific git `ref` (commit SHA, branch, or tag). Defaults to `main`.
123
- */
124
- export declare function defaultConfigUrl(network: Network, ref?: string): string;
125
115
  export declare function clearConfigCache(): void;
126
116
  export declare function loadConfig(network: Network, opts?: LoadConfigOptions): Promise<WaterXConfig>;
@@ -11,7 +11,6 @@
11
11
  */
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  exports.WORMHOLE_DEFAULTS = exports.PYTH_DEFAULTS = void 0;
14
- exports.defaultConfigUrl = defaultConfigUrl;
15
14
  exports.clearConfigCache = clearConfigCache;
16
15
  exports.loadConfig = loadConfig;
17
16
  var config_ts_1 = require("../oracle/config.js");
@@ -40,22 +39,15 @@ exports.WORMHOLE_DEFAULTS = {
40
39
  wormholescan_api: "https://api.testnet.wormholescan.io/api/v1",
41
40
  },
42
41
  };
43
- const CONFIG_REPO_RAW_BASE = "https://raw.githubusercontent.com/WaterXProtocol/waterx-config";
44
- /** Default git ref for the canonical config when none is pinned. */
45
- const DEFAULT_CONFIG_REF = "main";
46
- /**
47
- * Build the canonical config URL for `network`, optionally pinned to a
48
- * specific git `ref` (commit SHA, branch, or tag). Defaults to `main`.
49
- */
50
- function defaultConfigUrl(network, ref = DEFAULT_CONFIG_REF) {
51
- return `${CONFIG_REPO_RAW_BASE}/${ref}/${network.toLowerCase()}.json`;
52
- }
53
42
  const cache = new Map();
54
43
  function clearConfigCache() {
55
44
  cache.clear();
56
45
  }
57
46
  async function loadConfig(network, opts = {}) {
58
- const url = opts.configUrl ?? defaultConfigUrl(network, opts.configRef);
47
+ const url = opts.waterxConfigUrl;
48
+ if (!url) {
49
+ throw new Error("loadConfig: no config URL — pass opts.waterxConfigUrl");
50
+ }
59
51
  if (opts.cache && cache.has(url)) {
60
52
  return cache.get(url);
61
53
  }
@@ -1,6 +1,6 @@
1
1
  export { PerpClient } from "./client.ts";
2
2
  export type { CreateClientOptions } from "./client.ts";
3
- export { PYTH_DEFAULTS, WORMHOLE_DEFAULTS, clearConfigCache, defaultConfigUrl, loadConfig, } from "./config.ts";
3
+ export { PYTH_DEFAULTS, WORMHOLE_DEFAULTS, clearConfigCache, loadConfig } from "./config.ts";
4
4
  export type { BasePackageEntry, ConstantFeedEntry, WaterxReferralPackage, LoadConfigOptions, NativeCustodyAsset, NativeCustodyPackage, PythInfraConfig, PythRulePackage, PythSponsorRulePackage, SupraFeedEntry, SupraRulePackage, TestnetFaucetPackage, TrustedEmitterRow, WaterXConfig, WaterXPackages, WaterxCreditPackage, WaterxOraclePackage, WaterxPerpMarketEntry, WaterxPerpPackage, WaterxStakingPackage, WithdrawalQueuePackage, WlpPackage, WormholeBridgePackage, WormholeInfraConfig, WxaAccountPackage, } from "./config.ts";
5
5
  export { ACTION_ADD_PRE_ORDER, ACTION_CANCEL_ORDER, ACTION_CANCEL_PRE_ORDER, ACTION_CLOSE_POSITION, ACTION_DECREASE_POSITION, ACTION_DEPOSIT_COLLATERAL, ACTION_INCREASE_POSITION, ACTION_LIQUIDATE, ACTION_OPEN_POSITION, ACTION_PLACE_ORDER, ACTION_UPDATE_ORDER, ACTION_WITHDRAW_COLLATERAL, BPS_SCALE, CRYPTO_FEE_RATE, DOUBLE_SCALE, DRY_RUN_SENDER, FLOAT_SCALE, MAINTENANCE_MARGIN_RATE, ORDER_LIMIT_BUY, ORDER_LIMIT_SELL, ORDER_STOP_BUY, ORDER_STOP_SELL, ORDER_TAG_WILDCARD, PERM_ALL, PERM_ALL_TRADING, PERM_CANCEL_ORDER, PERM_CLOSE_POSITION, PERM_DECREASE_POSITION, PERM_DEPOSIT_COLLATERAL, PERM_INCREASE_POSITION, PERM_MINT_WLP, PERM_OPEN_POSITION, PERM_PLACE_ORDER, PERM_REDEEM_WLP, PERM_WITHDRAW_COLLATERAL, STAKING_PERM_DEPOSIT_STAKE, STAKING_PERM_REDEEM_STAKE, STAKING_PERM_CLAIM_REWARD, STAKING_PERM_ALL, STOCK_FEE_RATE, MS_PER_YEAR, SUI_DECIMALS, WLP_DECIMALS, COLLATERAL_DECIMALS, TOKEN_DECIMALS, } from "./constants.ts";
6
6
  export type { Network } from "./constants.ts";
@@ -36,9 +36,9 @@ 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.STOCK_FEE_RATE = 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.MAINTENANCE_MARGIN_RATE = exports.FLOAT_SCALE = exports.DRY_RUN_SENDER = exports.DOUBLE_SCALE = exports.CRYPTO_FEE_RATE = 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.defaultConfigUrl = exports.clearConfigCache = exports.WORMHOLE_DEFAULTS = exports.PYTH_DEFAULTS = exports.PerpClient = void 0;
40
- exports.PoolDataBcs = exports.OrderDataBcs = exports.MarketDataBcs = exports.GlobalConfigDataBcs = exports.AccountDataBcs = exports.waitForVaa = exports.vaaBytesToBase64 = 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.rawPrice = exports.decodeFundingIndexDelta = exports.calcWlpRedeemOut = exports.calcWlpPrice = exports.calcWlpMintOut = exports.calcWlpIncentiveApy = exports.calcUnrealizedPnl = exports.calcTotalTradingFeeRate = exports.calcTokenUtilizationBps = exports.calcPositionBorrowFee = exports.calcNotional = exports.calcMaxReducibleCollateralUsd = exports.calcLeverage = exports.calcImpactFeeRate = exports.calcFundingRate = exports.calcFundingFeeUsd = exports.calcFee = exports.calcEstLiqPrice = exports.calcEffectiveCollateralUsd = exports.calcDynamicFeeBps = exports.calcBorrowRateAccrual = exports.calcBorrowRate = exports.annualizeFundingRate = exports.annualizedApyFromRatio = exports.getCollateralAssets = exports.getMarketTickers = exports.TOKEN_DECIMALS = 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 = void 0;
39
+ exports.TOKEN_DECIMALS = exports.COLLATERAL_DECIMALS = exports.WLP_DECIMALS = exports.SUI_DECIMALS = exports.MS_PER_YEAR = exports.STOCK_FEE_RATE = 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.MAINTENANCE_MARGIN_RATE = exports.FLOAT_SCALE = exports.DRY_RUN_SENDER = exports.DOUBLE_SCALE = exports.CRYPTO_FEE_RATE = 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.PositionDataBcs = exports.PoolDataBcs = exports.OrderDataBcs = exports.MarketDataBcs = exports.GlobalConfigDataBcs = exports.AccountDataBcs = exports.waitForVaa = exports.vaaBytesToBase64 = 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.rawPrice = exports.decodeFundingIndexDelta = exports.calcWlpRedeemOut = exports.calcWlpPrice = exports.calcWlpMintOut = exports.calcWlpIncentiveApy = exports.calcUnrealizedPnl = exports.calcTotalTradingFeeRate = exports.calcTokenUtilizationBps = exports.calcPositionBorrowFee = exports.calcNotional = exports.calcMaxReducibleCollateralUsd = exports.calcLeverage = exports.calcImpactFeeRate = exports.calcFundingRate = exports.calcFundingFeeUsd = exports.calcFee = exports.calcEstLiqPrice = exports.calcEffectiveCollateralUsd = exports.calcDynamicFeeBps = exports.calcBorrowRateAccrual = exports.calcBorrowRate = exports.annualizeFundingRate = exports.annualizedApyFromRatio = exports.getCollateralAssets = exports.getMarketTickers = 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 = 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; } });
@@ -46,7 +46,6 @@ 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
47
  Object.defineProperty(exports, "WORMHOLE_DEFAULTS", { enumerable: true, get: function () { return config_ts_1.WORMHOLE_DEFAULTS; } });
48
48
  Object.defineProperty(exports, "clearConfigCache", { enumerable: true, get: function () { return config_ts_1.clearConfigCache; } });
49
- Object.defineProperty(exports, "defaultConfigUrl", { enumerable: true, get: function () { return config_ts_1.defaultConfigUrl; } });
50
49
  Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return config_ts_1.loadConfig; } });
51
50
  // ======== Constants & enums ========
52
51
  var constants_ts_1 = require("./constants.js");
@@ -40,6 +40,17 @@ export declare class PredictClient extends BaseLineClient<WaterxPredictionConfig
40
40
  waterxAccountAdminCap(): string;
41
41
  waterxPredictionGiftPackageId(): string;
42
42
  claimableLinkConfigId(): string;
43
+ /**
44
+ * Original (first-published) id of the gift package. Used ONLY for the
45
+ * `GiftKey` type tag in derived-object address computation
46
+ * (`deriveGiftAddress`). Sui pins a struct's type identity to its
47
+ * defining package's *original* id — it never advances across upgrades,
48
+ * unlike `published_at`. So the off-chain `gift_id` derivation must key
49
+ * on this, or it diverges from the on-chain `derive_gift_address` after
50
+ * the first upgrade. Falls back to `published_at` when `original_id` is
51
+ * absent (fresh deployments where the two are equal).
52
+ */
53
+ waterxPredictionGiftTypeOriginId(): string;
43
54
  waterxReferralPackageId(): string;
44
55
  referralTableId(): string;
45
56
  }
@@ -71,6 +71,22 @@ class PredictClient extends base_client_ts_1.BaseLineClient {
71
71
  claimableLinkConfigId() {
72
72
  return requireConfigValue(this.config.packages.waterx_prediction_gift, "claimable_link_config", "packages.waterx_prediction_gift.claimable_link_config");
73
73
  }
74
+ /**
75
+ * Original (first-published) id of the gift package. Used ONLY for the
76
+ * `GiftKey` type tag in derived-object address computation
77
+ * (`deriveGiftAddress`). Sui pins a struct's type identity to its
78
+ * defining package's *original* id — it never advances across upgrades,
79
+ * unlike `published_at`. So the off-chain `gift_id` derivation must key
80
+ * on this, or it diverges from the on-chain `derive_gift_address` after
81
+ * the first upgrade. Falls back to `published_at` when `original_id` is
82
+ * absent (fresh deployments where the two are equal).
83
+ */
84
+ waterxPredictionGiftTypeOriginId() {
85
+ const origin = this.config.packages.waterx_prediction_gift?.original_id;
86
+ return typeof origin === "string" && origin.length > 0
87
+ ? origin
88
+ : this.waterxPredictionGiftPackageId();
89
+ }
74
90
  waterxReferralPackageId() {
75
91
  return requireConfigValue(this.config.packages.waterx_referral, "published_at", "packages.waterx_referral.published_at");
76
92
  }
@@ -47,17 +47,12 @@ export interface WaterxPredictionConfig {
47
47
  }
48
48
  export interface LoadConfigOptions {
49
49
  /**
50
- * Override the default waterx-config raw JSON URL. Use this to point at a
51
- * local mirror during development. Takes precedence over {@link configRef}.
50
+ * Canonical `waterx-config` JSON URL to fetch, **as-is** (no `<network>.json`
51
+ * / git ref appended). Required {@link loadConfig} reads the URL only from
52
+ * this option (there is no env-var fallback and no built-in default) and
53
+ * throws when it is unset.
52
54
  */
53
- configUrl?: string;
54
- /**
55
- * Pin the canonical config to a specific git ref — a commit SHA, branch, or
56
- * tag — instead of the default `main` branch. Resolves to
57
- * `https://raw.githubusercontent.com/WaterXProtocol/waterx-config/<ref>/<network>.json`.
58
- * Ignored when {@link configUrl} is set.
59
- */
60
- configRef?: string;
55
+ waterxConfigUrl?: string;
61
56
  /** Reuse a previously fetched config in memory. Default: false. */
62
57
  cache?: boolean;
63
58
  /** Optional fetch implementation for tests or runtimes without global fetch. */
@@ -65,10 +60,5 @@ export interface LoadConfigOptions {
65
60
  /** Request timeout in ms. Default: 10_000. */
66
61
  timeoutMs?: number;
67
62
  }
68
- /**
69
- * Build the canonical config URL for `network`, optionally pinned to a
70
- * specific git `ref` (commit SHA, branch, or tag). Defaults to `main`.
71
- */
72
- export declare function defaultConfigUrl(network: Network, ref?: string): string;
73
63
  export declare function clearConfigCache(): void;
74
64
  export declare function loadConfig(network: Network, opts?: LoadConfigOptions): Promise<WaterxPredictionConfig>;
@@ -6,25 +6,17 @@
6
6
  * and fetches it from GitHub raw by default.
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.defaultConfigUrl = defaultConfigUrl;
10
9
  exports.clearConfigCache = clearConfigCache;
11
10
  exports.loadConfig = loadConfig;
12
- const CONFIG_REPO_RAW_BASE = "https://raw.githubusercontent.com/WaterXProtocol/waterx-config";
13
- /** Default git ref for the canonical config when none is pinned. */
14
- const DEFAULT_CONFIG_REF = "main";
15
- /**
16
- * Build the canonical config URL for `network`, optionally pinned to a
17
- * specific git `ref` (commit SHA, branch, or tag). Defaults to `main`.
18
- */
19
- function defaultConfigUrl(network, ref = DEFAULT_CONFIG_REF) {
20
- return `${CONFIG_REPO_RAW_BASE}/${ref}/${network.toLowerCase()}.json`;
21
- }
22
11
  const configCache = new Map();
23
12
  function clearConfigCache() {
24
13
  configCache.clear();
25
14
  }
26
15
  async function loadConfig(network, opts = {}) {
27
- const url = opts.configUrl ?? defaultConfigUrl(network, opts.configRef);
16
+ const url = opts.waterxConfigUrl;
17
+ if (!url) {
18
+ throw new Error("loadConfig: no config URL — pass opts.waterxConfigUrl");
19
+ }
28
20
  if (opts.cache && configCache.has(url)) {
29
21
  return configCache.get(url);
30
22
  }
@@ -1,5 +1,5 @@
1
1
  import type { PredictClient } from "./client.ts";
2
- import type { AccountDataView, CursorView, MarketExposure, MarketIdInput, MarketView, OrderView, PositionView, RegistryView } from "./types.ts";
2
+ import type { AccountDataView, CursorView, MarketExposure, MarketIdInput, MarketPage, MarketView, OrderView, PageParams, PositionPage, PositionView, RegistryView } from "./types.ts";
3
3
  export declare function extractReturnBytes(result: any, commandIndex?: number, returnIndex?: number): Uint8Array;
4
4
  export interface ViewBaseParams {
5
5
  packageId?: string;
@@ -30,6 +30,11 @@ export declare function getOrderCursor(client: PredictClient, params?: ViewBaseP
30
30
  export declare function getPositionCursor(client: PredictClient, params?: ViewBaseParams): Promise<CursorView>;
31
31
  export declare function getUnresolvedMarketCursor(client: PredictClient, params?: ViewBaseParams): Promise<CursorView>;
32
32
  export declare function getResolvedMarketCursor(client: PredictClient, params?: ViewBaseParams): Promise<CursorView>;
33
+ /** Every unresolved (active) market in one call. Prefer `getUnresolvedMarketsPage` when the table is large. */
34
+ export declare function getUnresolvedMarkets(client: PredictClient, params?: ViewBaseParams): Promise<MarketView[]>;
35
+ export declare function getUnresolvedMarketsPage(client: PredictClient, params?: PageParams): Promise<MarketPage>;
36
+ export declare function getResolvedMarketsPage(client: PredictClient, params?: PageParams): Promise<MarketPage>;
37
+ export declare function getPositionsPage(client: PredictClient, params?: PageParams): Promise<PositionPage>;
33
38
  export interface GetAccountIdsParams {
34
39
  /** Wallet address that owns sub-accounts in the registry. */
35
40
  owner: string;
@@ -12,6 +12,10 @@ exports.getOrderCursor = getOrderCursor;
12
12
  exports.getPositionCursor = getPositionCursor;
13
13
  exports.getUnresolvedMarketCursor = getUnresolvedMarketCursor;
14
14
  exports.getResolvedMarketCursor = getResolvedMarketCursor;
15
+ exports.getUnresolvedMarkets = getUnresolvedMarkets;
16
+ exports.getUnresolvedMarketsPage = getUnresolvedMarketsPage;
17
+ exports.getResolvedMarketsPage = getResolvedMarketsPage;
18
+ exports.getPositionsPage = getPositionsPage;
15
19
  exports.getAccountIds = getAccountIds;
16
20
  exports.getAccountData = getAccountData;
17
21
  exports.getAccountOrderIds = getAccountOrderIds;
@@ -149,6 +153,66 @@ function getUnresolvedMarketCursor(client, params = {}) {
149
153
  function getResolvedMarketCursor(client, params = {}) {
150
154
  return readCursor(client, "resolved_market_cursor", params);
151
155
  }
156
+ const DEFAULT_PAGE_LIMIT = 100n;
157
+ /** Encode an optional cursor key as a Move `Option<u64>` pure arg (`undefined` → none / from front). */
158
+ function startArg(tx, start) {
159
+ return tx.pure(bcs_1.bcs.option(bcs_1.bcs.u64()).serialize(start === undefined ? null : (0, utils_ts_1.toBigInt)(start)));
160
+ }
161
+ /** Every unresolved (active) market in one call. Prefer `getUnresolvedMarketsPage` when the table is large. */
162
+ async function getUnresolvedMarkets(client, params = {}) {
163
+ const tx = new transactions_1.Transaction();
164
+ tx.moveCall({
165
+ target: `${(0, utils_ts_1.resolvePackageId)(client, params.packageId)}::view::unresolved_markets`,
166
+ typeArguments: [(0, utils_ts_1.resolveSettlementCoinType)(client, params.settlementCoinType)],
167
+ arguments: [tx.object((0, utils_ts_1.resolveMarketRegistry)(client, params.marketRegistry))],
168
+ });
169
+ const result = await client.simulate(tx);
170
+ return bcs_1.bcs.vector(bcs_ts_1.MarketViewBcs).parse(extractReturnBytes(result)).map(bcs_ts_1.mapMarketView);
171
+ }
172
+ async function readMarketsPage(client, functionName, params = {}) {
173
+ const tx = new transactions_1.Transaction();
174
+ tx.moveCall({
175
+ target: `${(0, utils_ts_1.resolvePackageId)(client, params.packageId)}::view::${functionName}`,
176
+ typeArguments: [(0, utils_ts_1.resolveSettlementCoinType)(client, params.settlementCoinType)],
177
+ arguments: [
178
+ tx.object((0, utils_ts_1.resolveMarketRegistry)(client, params.marketRegistry)),
179
+ startArg(tx, params.start),
180
+ tx.pure.u64(params.limit === undefined ? DEFAULT_PAGE_LIMIT : (0, utils_ts_1.toBigInt)(params.limit)),
181
+ ],
182
+ });
183
+ const result = await client.simulate(tx);
184
+ const markets = bcs_1.bcs
185
+ .vector(bcs_ts_1.MarketViewBcs)
186
+ .parse(extractReturnBytes(result, 0, 0))
187
+ .map(bcs_ts_1.mapMarketView);
188
+ const next = bcs_1.bcs.option(bcs_1.bcs.u64()).parse(extractReturnBytes(result, 0, 1));
189
+ return { markets, nextCursor: next == null ? null : BigInt(next) };
190
+ }
191
+ function getUnresolvedMarketsPage(client, params = {}) {
192
+ return readMarketsPage(client, "unresolved_markets_page", params);
193
+ }
194
+ function getResolvedMarketsPage(client, params = {}) {
195
+ return readMarketsPage(client, "resolved_markets_page", params);
196
+ }
197
+ async function getPositionsPage(client, params = {}) {
198
+ const tx = new transactions_1.Transaction();
199
+ tx.moveCall({
200
+ target: `${(0, utils_ts_1.resolvePackageId)(client, params.packageId)}::view::positions_page`,
201
+ typeArguments: [(0, utils_ts_1.resolveSettlementCoinType)(client, params.settlementCoinType)],
202
+ arguments: [
203
+ tx.object((0, utils_ts_1.resolveMarketRegistry)(client, params.marketRegistry)),
204
+ startArg(tx, params.start),
205
+ tx.pure.u64(params.limit === undefined ? DEFAULT_PAGE_LIMIT : (0, utils_ts_1.toBigInt)(params.limit)),
206
+ ],
207
+ });
208
+ const result = await client.simulate(tx);
209
+ const positions = bcs_1.bcs
210
+ .vector(bcs_ts_1.PositionViewBcs)
211
+ .parse(extractReturnBytes(result, 0, 0))
212
+ .map(bcs_ts_1.mapPositionView);
213
+ const next = bcs_1.bcs.option(bcs_1.bcs.u64()).parse(extractReturnBytes(result, 0, 1));
214
+ return { positions, nextCursor: next == null ? null : BigInt(next) };
215
+ }
152
216
  /**
153
217
  * Registry account ids (`0x2::object::ID`) for an owner via `waterx_account::account::account_ids`.
154
218
  * Use these ids with `getAccountData`, `deposit`, and `placeOrder` — not Suiscan "Account" object addresses.
@@ -25,6 +25,16 @@ import type { AccountIdentityParams, IdArgument, Selection } from "./types.ts";
25
25
  export interface GiftBaseParams {
26
26
  /** `waterx_prediction_gift` package id. Defaults to `client.waterxPredictionGiftPackageId()`. */
27
27
  giftPackageId?: string;
28
+ /**
29
+ * `waterx_prediction_gift` *original* (first-published) package id, used
30
+ * ONLY for the `GiftKey` type tag in {@link deriveGiftAddress}. Defaults to
31
+ * `client.waterxPredictionGiftTypeOriginId()` (config `original_id`, falling
32
+ * back to `giftPackageId`/`published_at`). Distinct from `giftPackageId`,
33
+ * which selects the *runtime* package for moveCall targets — after a package
34
+ * upgrade the two diverge, and only the original id reproduces the on-chain
35
+ * `gift_id`. Override only for offline derivation against a custom deploy.
36
+ */
37
+ giftTypeOriginId?: string;
28
38
  /** `ClaimableLinkConfig` object id. Defaults to `client.claimableLinkConfigId()`. */
29
39
  claimableLinkConfig?: string;
30
40
  /** Collateral / settlement coin type for the position's `Gift<T>`. Defaults to `client.settlementCoinType()`. */
@@ -72,6 +82,15 @@ export declare function signGiftClaim(giftKeypair: Ed25519Keypair, giftId: strin
72
82
  /**
73
83
  * Compute the `gift_id` that `create_gift` will produce for the given
74
84
  * pubkey, offline. No RPC. Mirrors `claimable_link::derive_gift_address`.
85
+ *
86
+ * The `GiftKey` type tag is keyed on the gift package's *original* id
87
+ * (via {@link resolveGiftTypeOriginId}), NOT `published_at`. On Sui a
88
+ * struct's type identity stays pinned to its defining package's original
89
+ * id and never advances across upgrades, so `derive_gift_address`
90
+ * hashes `GiftKey` under that original id. Using `published_at` here would
91
+ * silently diverge from the chain after the first package upgrade, yielding
92
+ * the wrong `gift_id` for every gift. The moveCall targets elsewhere in
93
+ * this module correctly stay on `published_at` (latest code).
75
94
  */
76
95
  export declare function deriveGiftAddress(client: PredictClient, pubkey: Uint8Array, params?: GiftBaseParams): string;
77
96
  export interface CreateGiftParams extends GiftBaseParams, GiftReferralParams, AccountIdentityParams {
@@ -54,6 +54,22 @@ function resolveGiftPackageId(client, override) {
54
54
  ? client.waterxPredictionGiftPackageId()
55
55
  : override;
56
56
  }
57
+ /**
58
+ * Resolve the package id for the `GiftKey` type tag in
59
+ * {@link deriveGiftAddress}. Precedence: explicit `giftTypeOriginId`, then
60
+ * the runtime `giftPackageId` override (a self-contained deploy where
61
+ * original == published), then the client's config `original_id` (falling
62
+ * back to `published_at`). This must key on the *original* id so the
63
+ * off-chain derivation matches the on-chain type identity, which never
64
+ * advances across package upgrades.
65
+ */
66
+ function resolveGiftTypeOriginId(client, originOverride, pkgOverride) {
67
+ if (originOverride !== undefined && originOverride !== "")
68
+ return originOverride;
69
+ if (pkgOverride !== undefined && pkgOverride !== "")
70
+ return pkgOverride;
71
+ return client.waterxPredictionGiftTypeOriginId();
72
+ }
57
73
  function resolveClaimableLinkConfig(client, override) {
58
74
  return override === undefined || override === "" ? client.claimableLinkConfigId() : override;
59
75
  }
@@ -167,12 +183,21 @@ const GiftKeyBcs = bcs_1.bcs.struct("GiftKey", {
167
183
  /**
168
184
  * Compute the `gift_id` that `create_gift` will produce for the given
169
185
  * pubkey, offline. No RPC. Mirrors `claimable_link::derive_gift_address`.
186
+ *
187
+ * The `GiftKey` type tag is keyed on the gift package's *original* id
188
+ * (via {@link resolveGiftTypeOriginId}), NOT `published_at`. On Sui a
189
+ * struct's type identity stays pinned to its defining package's original
190
+ * id and never advances across upgrades, so `derive_gift_address`
191
+ * hashes `GiftKey` under that original id. Using `published_at` here would
192
+ * silently diverge from the chain after the first package upgrade, yielding
193
+ * the wrong `gift_id` for every gift. The moveCall targets elsewhere in
194
+ * this module correctly stay on `published_at` (latest code).
170
195
  */
171
196
  function deriveGiftAddress(client, pubkey, params = {}) {
172
197
  if (pubkey.length !== constants_ts_1.GIFT_PUBKEY_LEN) {
173
198
  throw new Error(`Gift pubkey must be ${constants_ts_1.GIFT_PUBKEY_LEN} bytes, got ${pubkey.length}`);
174
199
  }
175
- const giftPkg = resolveGiftPackageId(client, params.giftPackageId);
200
+ const giftPkg = resolveGiftTypeOriginId(client, params.giftTypeOriginId, params.giftPackageId);
176
201
  const configId = resolveClaimableLinkConfig(client, params.claimableLinkConfig);
177
202
  const keyBytes = GiftKeyBcs.serialize({ pubkey: Array.from(pubkey) }).toBytes();
178
203
  return (0, utils_1.deriveObjectID)(configId, `${giftPkg}::claimable_link::GiftKey`, keyBytes);
@@ -1,6 +1,6 @@
1
1
  export { PredictClient } from "./client.ts";
2
2
  export type { CreateClientOptions } from "./client.ts";
3
- export { clearConfigCache, defaultConfigUrl, loadConfig } from "./config.ts";
3
+ export { clearConfigCache, loadConfig } from "./config.ts";
4
4
  export type { LoadConfigOptions, WaterxAccountPackage, WaterxConfigPackageBase, WaterxPredictionConfig, WaterxPredictionConfigPackages, WaterxPredictionGiftPackage, WaterxPredictionPackage, WaterxReferralPackage, } from "./config.ts";
5
5
  export * from "./constants.ts";
6
6
  export * from "./types.ts";
@@ -14,7 +14,7 @@ export { adminPlaceOrderFor, batchClaim, batchForceClaim, buildBatchForceClaimTr
14
14
  export type { AdminPlaceOrderForParams, BatchClaimParams, BatchForceClaimParams, BuildBatchForceClaimTransactionsParams, CancelCloseParams, CancelOrderParams, ClaimParams, ConfirmCloseParams, FillOrderParams, ForceClaimParams, PlaceOrderParams, RequestCloseParams, RequestPartialCloseParams, ResolveMarketParams, SelfCancelCloseParams, SelfCancelOrderParams, SplitPositionParams, TransferPositionParams, } from "./prediction.ts";
15
15
  export { buildBatchClaimTx, buildPlaceOrderTx } from "./tx-builders.ts";
16
16
  export type { BuildBatchClaimTxParams, BuildPlaceOrderTxParams, PredictCommonBuildOpts, } from "./tx-builders.ts";
17
- export { getAccountData, getAccountIds, getAccountOrderIds, getAccountOrderIdsByMarketId, getAccountPositionIds, getAccountPositionIdsByMarketId, getKeeperAddresses, getAllowedVersions, getMarketExposure, getMarketExposureByKey, getMarketById, getMarketByKey, getOrder, getOrderCursor, getPosition, getPositionCursor, getRegistry, getResolvedMarketCursor, getUnresolvedMarketCursor, isKeeper, isPredictionProtocolAssetAllowed, } from "./fetch.ts";
17
+ export { getAccountData, getAccountIds, getAccountOrderIds, getAccountOrderIdsByMarketId, getAccountPositionIds, getAccountPositionIdsByMarketId, getKeeperAddresses, getAllowedVersions, getMarketExposure, getMarketExposureByKey, getMarketById, getMarketByKey, getOrder, getOrderCursor, getPosition, getPositionCursor, getPositionsPage, getRegistry, getResolvedMarketCursor, getResolvedMarketsPage, getUnresolvedMarketCursor, getUnresolvedMarkets, getUnresolvedMarketsPage, isKeeper, isPredictionProtocolAssetAllowed, } from "./fetch.ts";
18
18
  export type { GetAccountIdsParams, ViewBaseParams } from "./fetch.ts";
19
19
  export { base64UrlNoPadDecode, base64UrlNoPadEncode, buildClaimShareFlow, buildCreateGiftFlow, buildGiftClaimMessage, claimShare, createGift, deleteGift, deriveGiftAddress, deriveGiftKeypair, encodeGiftUrl, generateGiftSeed, getCreatorGiftCount, getCreatorGiftIds, getGift, getGiftConfigPaused, getGiftControllerAddress, getGiftHasClaimed, parseGiftUrl, signGiftClaim, } from "./gift.ts";
20
20
  export type { BuildClaimShareFlowParams, BuildClaimShareFlowResult, BuildCreateGiftFlowResult, ClaimShareParams, CreateGiftParams, DeleteGiftParams, GiftBaseParams, GiftReferralParams, GiftUrlParts, GiftView, } from "./gift.ts";
@@ -36,14 +36,13 @@ var __importStar = (this && this.__importStar) || (function () {
36
36
  };
37
37
  })();
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.splitPosition = exports.selfCancelOrder = exports.selfCancelClose = exports.selectionArg = exports.resolveMarket = exports.requestPartialClose = exports.requestClose = exports.placeOrder = exports.outcomeArg = exports.forceClaim = exports.fillOrder = exports.confirmClose = exports.claim = exports.cancelOrder = exports.cancelClose = exports.buildBatchForceClaimTransactions = exports.batchForceClaim = exports.batchClaim = exports.adminPlaceOrderFor = exports.unpauseMarket = exports.setOrderCancelCooldownMs = exports.setMinReserve = exports.removeKeeper = exports.pauseMarket = exports.depositSettlement = exports.createMarketRegistry = exports.adminWithdraw = exports.addKeeper = exports.withdraw = exports.whitelistPredictionProtocol = exports.transferCoinToAccount = exports.setDelegatePredictionPermission = exports.requestWithdraw = exports.requestDepositFromReceivings = exports.requestDeposit = exports.resolveRegistryAccountId = exports.removeDelegate = exports.disallowPredictionProtocolAsset = exports.deposit = exports.createAccount = exports.consumeWithdrawDirect = exports.consumeDepositDirect = exports.allowPredictionProtocolAsset = exports.addDelegate = exports.utils = exports.user = exports.loadConfig = exports.defaultConfigUrl = exports.clearConfigCache = exports.PredictClient = void 0;
40
- exports.predictionPositionCalls = exports.predictionOutcomeCalls = exports.predictionGlobalConfigCalls = exports.predictionAccountDataCalls = exports.waterxAccountCalls = exports.bucketFrameworkAccountCalls = exports.signGiftClaim = exports.parseGiftUrl = exports.getGiftHasClaimed = exports.getGiftControllerAddress = exports.getGiftConfigPaused = exports.getGift = exports.getCreatorGiftIds = exports.getCreatorGiftCount = exports.generateGiftSeed = exports.encodeGiftUrl = exports.deriveGiftKeypair = exports.deriveGiftAddress = exports.deleteGift = exports.createGift = exports.claimShare = exports.buildGiftClaimMessage = exports.buildCreateGiftFlow = exports.buildClaimShareFlow = exports.base64UrlNoPadEncode = exports.base64UrlNoPadDecode = exports.isPredictionProtocolAssetAllowed = exports.isKeeper = exports.getUnresolvedMarketCursor = exports.getResolvedMarketCursor = exports.getRegistry = exports.getPositionCursor = exports.getPosition = exports.getOrderCursor = exports.getOrder = exports.getMarketByKey = exports.getMarketById = exports.getMarketExposureByKey = exports.getMarketExposure = exports.getAllowedVersions = exports.getKeeperAddresses = exports.getAccountPositionIdsByMarketId = exports.getAccountPositionIds = exports.getAccountOrderIdsByMarketId = exports.getAccountOrderIds = exports.getAccountIds = exports.getAccountData = exports.buildPlaceOrderTx = exports.buildBatchClaimTx = exports.transferPosition = void 0;
41
- exports.predictionCalls = exports.predictionViewCalls = exports.predictionVersionCalls = void 0;
39
+ exports.transferPosition = exports.splitPosition = exports.selfCancelOrder = exports.selfCancelClose = exports.selectionArg = exports.resolveMarket = exports.requestPartialClose = exports.requestClose = exports.placeOrder = exports.outcomeArg = exports.forceClaim = exports.fillOrder = exports.confirmClose = exports.claim = exports.cancelOrder = exports.cancelClose = exports.buildBatchForceClaimTransactions = exports.batchForceClaim = exports.batchClaim = exports.adminPlaceOrderFor = exports.unpauseMarket = exports.setOrderCancelCooldownMs = exports.setMinReserve = exports.removeKeeper = exports.pauseMarket = exports.depositSettlement = exports.createMarketRegistry = exports.adminWithdraw = exports.addKeeper = exports.withdraw = exports.whitelistPredictionProtocol = exports.transferCoinToAccount = exports.setDelegatePredictionPermission = exports.requestWithdraw = exports.requestDepositFromReceivings = exports.requestDeposit = exports.resolveRegistryAccountId = exports.removeDelegate = exports.disallowPredictionProtocolAsset = exports.deposit = exports.createAccount = exports.consumeWithdrawDirect = exports.consumeDepositDirect = exports.allowPredictionProtocolAsset = exports.addDelegate = exports.utils = exports.user = exports.loadConfig = exports.clearConfigCache = exports.PredictClient = void 0;
40
+ exports.predictionAccountDataCalls = exports.waterxAccountCalls = exports.bucketFrameworkAccountCalls = exports.signGiftClaim = exports.parseGiftUrl = exports.getGiftHasClaimed = exports.getGiftControllerAddress = exports.getGiftConfigPaused = exports.getGift = exports.getCreatorGiftIds = exports.getCreatorGiftCount = exports.generateGiftSeed = exports.encodeGiftUrl = exports.deriveGiftKeypair = exports.deriveGiftAddress = exports.deleteGift = exports.createGift = exports.claimShare = exports.buildGiftClaimMessage = exports.buildCreateGiftFlow = exports.buildClaimShareFlow = exports.base64UrlNoPadEncode = exports.base64UrlNoPadDecode = exports.isPredictionProtocolAssetAllowed = exports.isKeeper = exports.getUnresolvedMarketsPage = exports.getUnresolvedMarkets = exports.getUnresolvedMarketCursor = exports.getResolvedMarketsPage = exports.getResolvedMarketCursor = exports.getRegistry = exports.getPositionsPage = exports.getPositionCursor = exports.getPosition = exports.getOrderCursor = exports.getOrder = exports.getMarketByKey = exports.getMarketById = exports.getMarketExposureByKey = exports.getMarketExposure = exports.getAllowedVersions = exports.getKeeperAddresses = exports.getAccountPositionIdsByMarketId = exports.getAccountPositionIds = exports.getAccountOrderIdsByMarketId = exports.getAccountOrderIds = exports.getAccountIds = exports.getAccountData = exports.buildPlaceOrderTx = exports.buildBatchClaimTx = void 0;
41
+ exports.predictionCalls = exports.predictionViewCalls = exports.predictionVersionCalls = exports.predictionPositionCalls = exports.predictionOutcomeCalls = exports.predictionGlobalConfigCalls = void 0;
42
42
  var client_ts_1 = require("./client.js");
43
43
  Object.defineProperty(exports, "PredictClient", { enumerable: true, get: function () { return client_ts_1.PredictClient; } });
44
44
  var config_ts_1 = require("./config.js");
45
45
  Object.defineProperty(exports, "clearConfigCache", { enumerable: true, get: function () { return config_ts_1.clearConfigCache; } });
46
- Object.defineProperty(exports, "defaultConfigUrl", { enumerable: true, get: function () { return config_ts_1.defaultConfigUrl; } });
47
46
  Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return config_ts_1.loadConfig; } });
48
47
  __exportStar(require("./constants.js"), exports);
49
48
  __exportStar(require("./types.js"), exports);
@@ -117,9 +116,13 @@ Object.defineProperty(exports, "getOrder", { enumerable: true, get: function ()
117
116
  Object.defineProperty(exports, "getOrderCursor", { enumerable: true, get: function () { return fetch_ts_1.getOrderCursor; } });
118
117
  Object.defineProperty(exports, "getPosition", { enumerable: true, get: function () { return fetch_ts_1.getPosition; } });
119
118
  Object.defineProperty(exports, "getPositionCursor", { enumerable: true, get: function () { return fetch_ts_1.getPositionCursor; } });
119
+ Object.defineProperty(exports, "getPositionsPage", { enumerable: true, get: function () { return fetch_ts_1.getPositionsPage; } });
120
120
  Object.defineProperty(exports, "getRegistry", { enumerable: true, get: function () { return fetch_ts_1.getRegistry; } });
121
121
  Object.defineProperty(exports, "getResolvedMarketCursor", { enumerable: true, get: function () { return fetch_ts_1.getResolvedMarketCursor; } });
122
+ Object.defineProperty(exports, "getResolvedMarketsPage", { enumerable: true, get: function () { return fetch_ts_1.getResolvedMarketsPage; } });
122
123
  Object.defineProperty(exports, "getUnresolvedMarketCursor", { enumerable: true, get: function () { return fetch_ts_1.getUnresolvedMarketCursor; } });
124
+ Object.defineProperty(exports, "getUnresolvedMarkets", { enumerable: true, get: function () { return fetch_ts_1.getUnresolvedMarkets; } });
125
+ Object.defineProperty(exports, "getUnresolvedMarketsPage", { enumerable: true, get: function () { return fetch_ts_1.getUnresolvedMarketsPage; } });
123
126
  Object.defineProperty(exports, "isKeeper", { enumerable: true, get: function () { return fetch_ts_1.isKeeper; } });
124
127
  Object.defineProperty(exports, "isPredictionProtocolAssetAllowed", { enumerable: true, get: function () { return fetch_ts_1.isPredictionProtocolAssetAllowed; } });
125
128
  var gift_ts_1 = require("./gift.js");
@@ -88,6 +88,25 @@ export interface CursorView {
88
88
  front: bigint | null;
89
89
  back: bigint | null;
90
90
  }
91
+ export interface PageParams {
92
+ packageId?: string;
93
+ marketRegistry?: string;
94
+ settlementCoinType?: string;
95
+ /** Cursor key to resume from; omit to start at the front of the table. */
96
+ start?: bigint | number | string;
97
+ /** Max entries in this page (default 100). */
98
+ limit?: bigint | number | string;
99
+ }
100
+ export interface MarketPage {
101
+ markets: MarketView[];
102
+ /** Pass as `start` for the next page; `null` when the table is exhausted. */
103
+ nextCursor: bigint | null;
104
+ }
105
+ export interface PositionPage {
106
+ positions: PositionView[];
107
+ /** Pass as `start` for the next page; `null` when the table is exhausted. */
108
+ nextCursor: bigint | null;
109
+ }
91
110
  export interface CoinRef {
92
111
  objectId: string;
93
112
  version: string | bigint | number;
@@ -263,6 +263,10 @@ declare const predictOps: {
263
263
  getPositionCursor(client: PredictClient, params?: predFetch.ViewBaseParams): Promise<import("./prediction/types.ts").CursorView>;
264
264
  getUnresolvedMarketCursor(client: PredictClient, params?: predFetch.ViewBaseParams): Promise<import("./prediction/types.ts").CursorView>;
265
265
  getResolvedMarketCursor(client: PredictClient, params?: predFetch.ViewBaseParams): Promise<import("./prediction/types.ts").CursorView>;
266
+ getUnresolvedMarkets(client: PredictClient, params?: predFetch.ViewBaseParams): Promise<import("./prediction/types.ts").MarketView[]>;
267
+ getUnresolvedMarketsPage(client: PredictClient, params?: import("./prediction/types.ts").PageParams): Promise<import("./prediction/types.ts").MarketPage>;
268
+ getResolvedMarketsPage(client: PredictClient, params?: import("./prediction/types.ts").PageParams): Promise<import("./prediction/types.ts").MarketPage>;
269
+ getPositionsPage(client: PredictClient, params?: import("./prediction/types.ts").PageParams): Promise<import("./prediction/types.ts").PositionPage>;
266
270
  getAccountIds(client: PredictClient, params: predFetch.GetAccountIdsParams): Promise<string[]>;
267
271
  getAccountData(client: PredictClient, params: predFetch.ViewBaseParams & {
268
272
  accountId: string;
@@ -354,13 +358,14 @@ export interface ClientCreateOptions {
354
358
  network?: Network;
355
359
  /** Default gRPC URL for both lines. */
356
360
  grpcUrl?: string;
357
- /** Default `waterx-config` JSON URL for both lines. */
358
- configUrl?: string;
361
+ /** Default `waterx-config` JSON URL for both lines (fetched as-is). Required
362
+ * unless supplied per-line via `perp` / `predict`. */
363
+ waterxConfigUrl?: string;
359
364
  /** Memoize the fetched config JSON. */
360
365
  cache?: boolean;
361
- /** Perp-line overrides (network, grpcUrl, configUrl, cache, …). */
366
+ /** Perp-line overrides (network, grpcUrl, waterxConfigUrl, cache, …). */
362
367
  perp?: PerpLineOptions;
363
- /** Prediction-line overrides (network, grpcUrl, configUrl, cache, settlement, …). */
368
+ /** Prediction-line overrides (network, grpcUrl, waterxConfigUrl, cache, settlement, …). */
364
369
  predict?: PredictLineOptions;
365
370
  }
366
371
  export declare class WaterXClient {
@@ -202,13 +202,13 @@ class WaterXClient {
202
202
  }
203
203
  const perpClient = await client_ts_1.PerpClient.create(resolvedPerpNetwork, {
204
204
  grpcUrl: opts.grpcUrl,
205
- configUrl: opts.configUrl,
205
+ waterxConfigUrl: opts.waterxConfigUrl,
206
206
  cache: opts.cache,
207
207
  ...perpRest,
208
208
  });
209
209
  const predictClient = await client_ts_2.PredictClient.create(resolvedPredictNetwork, {
210
210
  grpcUrl: opts.grpcUrl,
211
- configUrl: opts.configUrl,
211
+ waterxConfigUrl: opts.waterxConfigUrl,
212
212
  cache: opts.cache,
213
213
  ...predictRest,
214
214
  });
@@ -95,18 +95,13 @@ export interface WaterXConfig {
95
95
  }
96
96
  export interface LoadConfigOptions {
97
97
  /**
98
- * Override the default config URL. Use this to point at a staging branch
99
- * (`?ref=staging`) or a local mirror during development. Takes precedence
100
- * over {@link configRef}.
98
+ * Canonical `waterx-config` JSON URL to fetch, **as-is** (no `<network>.json`
99
+ * / git ref appended). Required {@link loadConfig} reads the URL only from
100
+ * this option (there is no env-var fallback and no built-in default) and
101
+ * throws when it is unset. Point it at a staging deployment or local mirror
102
+ * as needed.
101
103
  */
102
- configUrl?: string;
103
- /**
104
- * Pin the canonical config to a specific git ref — a commit SHA, branch,
105
- * or tag — instead of the default `main` branch. Resolves to
106
- * `https://raw.githubusercontent.com/WaterXProtocol/waterx-config/<ref>/<network>.json`.
107
- * Ignored when {@link configUrl} is set.
108
- */
109
- configRef?: string;
104
+ waterxConfigUrl?: string;
110
105
  /**
111
106
  * Reuse a previously-fetched config from the in-memory cache (keyed by
112
107
  * the effective URL). Default: false (always fetch fresh).
@@ -117,10 +112,5 @@ export interface LoadConfigOptions {
117
112
  /** Optional request timeout in ms. Default 10_000. */
118
113
  timeoutMs?: number;
119
114
  }
120
- /**
121
- * Build the canonical config URL for `network`, optionally pinned to a
122
- * specific git `ref` (commit SHA, branch, or tag). Defaults to `main`.
123
- */
124
- export declare function defaultConfigUrl(network: Network, ref?: string): string;
125
115
  export declare function clearConfigCache(): void;
126
116
  export declare function loadConfig(network: Network, opts?: LoadConfigOptions): Promise<WaterXConfig>;
@@ -33,22 +33,15 @@ export const WORMHOLE_DEFAULTS = {
33
33
  wormholescan_api: "https://api.testnet.wormholescan.io/api/v1",
34
34
  },
35
35
  };
36
- const CONFIG_REPO_RAW_BASE = "https://raw.githubusercontent.com/WaterXProtocol/waterx-config";
37
- /** Default git ref for the canonical config when none is pinned. */
38
- const DEFAULT_CONFIG_REF = "main";
39
- /**
40
- * Build the canonical config URL for `network`, optionally pinned to a
41
- * specific git `ref` (commit SHA, branch, or tag). Defaults to `main`.
42
- */
43
- export function defaultConfigUrl(network, ref = DEFAULT_CONFIG_REF) {
44
- return `${CONFIG_REPO_RAW_BASE}/${ref}/${network.toLowerCase()}.json`;
45
- }
46
36
  const cache = new Map();
47
37
  export function clearConfigCache() {
48
38
  cache.clear();
49
39
  }
50
40
  export async function loadConfig(network, opts = {}) {
51
- const url = opts.configUrl ?? defaultConfigUrl(network, opts.configRef);
41
+ const url = opts.waterxConfigUrl;
42
+ if (!url) {
43
+ throw new Error("loadConfig: no config URL — pass opts.waterxConfigUrl");
44
+ }
52
45
  if (opts.cache && cache.has(url)) {
53
46
  return cache.get(url);
54
47
  }
@@ -1,6 +1,6 @@
1
1
  export { PerpClient } from "./client.ts";
2
2
  export type { CreateClientOptions } from "./client.ts";
3
- export { PYTH_DEFAULTS, WORMHOLE_DEFAULTS, clearConfigCache, defaultConfigUrl, loadConfig, } from "./config.ts";
3
+ export { PYTH_DEFAULTS, WORMHOLE_DEFAULTS, clearConfigCache, loadConfig } from "./config.ts";
4
4
  export type { BasePackageEntry, ConstantFeedEntry, WaterxReferralPackage, LoadConfigOptions, NativeCustodyAsset, NativeCustodyPackage, PythInfraConfig, PythRulePackage, PythSponsorRulePackage, SupraFeedEntry, SupraRulePackage, TestnetFaucetPackage, TrustedEmitterRow, WaterXConfig, WaterXPackages, WaterxCreditPackage, WaterxOraclePackage, WaterxPerpMarketEntry, WaterxPerpPackage, WaterxStakingPackage, WithdrawalQueuePackage, WlpPackage, WormholeBridgePackage, WormholeInfraConfig, WxaAccountPackage, } from "./config.ts";
5
5
  export { ACTION_ADD_PRE_ORDER, ACTION_CANCEL_ORDER, ACTION_CANCEL_PRE_ORDER, ACTION_CLOSE_POSITION, ACTION_DECREASE_POSITION, ACTION_DEPOSIT_COLLATERAL, ACTION_INCREASE_POSITION, ACTION_LIQUIDATE, ACTION_OPEN_POSITION, ACTION_PLACE_ORDER, ACTION_UPDATE_ORDER, ACTION_WITHDRAW_COLLATERAL, BPS_SCALE, CRYPTO_FEE_RATE, DOUBLE_SCALE, DRY_RUN_SENDER, FLOAT_SCALE, MAINTENANCE_MARGIN_RATE, ORDER_LIMIT_BUY, ORDER_LIMIT_SELL, ORDER_STOP_BUY, ORDER_STOP_SELL, ORDER_TAG_WILDCARD, PERM_ALL, PERM_ALL_TRADING, PERM_CANCEL_ORDER, PERM_CLOSE_POSITION, PERM_DECREASE_POSITION, PERM_DEPOSIT_COLLATERAL, PERM_INCREASE_POSITION, PERM_MINT_WLP, PERM_OPEN_POSITION, PERM_PLACE_ORDER, PERM_REDEEM_WLP, PERM_WITHDRAW_COLLATERAL, STAKING_PERM_DEPOSIT_STAKE, STAKING_PERM_REDEEM_STAKE, STAKING_PERM_CLAIM_REWARD, STAKING_PERM_ALL, STOCK_FEE_RATE, MS_PER_YEAR, SUI_DECIMALS, WLP_DECIMALS, COLLATERAL_DECIMALS, TOKEN_DECIMALS, } from "./constants.ts";
6
6
  export type { Network } from "./constants.ts";
@@ -1,6 +1,6 @@
1
1
  // ======== Core ========
2
2
  export { PerpClient } from "./client.js";
3
- export { PYTH_DEFAULTS, WORMHOLE_DEFAULTS, clearConfigCache, defaultConfigUrl, loadConfig, } from "./config.js";
3
+ export { PYTH_DEFAULTS, WORMHOLE_DEFAULTS, clearConfigCache, loadConfig } from "./config.js";
4
4
  // ======== Constants & enums ========
5
5
  export { ACTION_ADD_PRE_ORDER, ACTION_CANCEL_ORDER, ACTION_CANCEL_PRE_ORDER, ACTION_CLOSE_POSITION, ACTION_DECREASE_POSITION, ACTION_DEPOSIT_COLLATERAL, ACTION_INCREASE_POSITION, ACTION_LIQUIDATE, ACTION_OPEN_POSITION, ACTION_PLACE_ORDER, ACTION_UPDATE_ORDER, ACTION_WITHDRAW_COLLATERAL, BPS_SCALE, CRYPTO_FEE_RATE, DOUBLE_SCALE, DRY_RUN_SENDER, FLOAT_SCALE, MAINTENANCE_MARGIN_RATE, ORDER_LIMIT_BUY, ORDER_LIMIT_SELL, ORDER_STOP_BUY, ORDER_STOP_SELL, ORDER_TAG_WILDCARD, PERM_ALL, PERM_ALL_TRADING, PERM_CANCEL_ORDER, PERM_CLOSE_POSITION, PERM_DECREASE_POSITION, PERM_DEPOSIT_COLLATERAL, PERM_INCREASE_POSITION, PERM_MINT_WLP, PERM_OPEN_POSITION, PERM_PLACE_ORDER, PERM_REDEEM_WLP, PERM_WITHDRAW_COLLATERAL, STAKING_PERM_DEPOSIT_STAKE, STAKING_PERM_REDEEM_STAKE, STAKING_PERM_CLAIM_REWARD, STAKING_PERM_ALL, STOCK_FEE_RATE, MS_PER_YEAR, SUI_DECIMALS, WLP_DECIMALS, COLLATERAL_DECIMALS, TOKEN_DECIMALS, } from "./constants.js";
6
6
  // ======== Utilities ========
@@ -40,6 +40,17 @@ export declare class PredictClient extends BaseLineClient<WaterxPredictionConfig
40
40
  waterxAccountAdminCap(): string;
41
41
  waterxPredictionGiftPackageId(): string;
42
42
  claimableLinkConfigId(): string;
43
+ /**
44
+ * Original (first-published) id of the gift package. Used ONLY for the
45
+ * `GiftKey` type tag in derived-object address computation
46
+ * (`deriveGiftAddress`). Sui pins a struct's type identity to its
47
+ * defining package's *original* id — it never advances across upgrades,
48
+ * unlike `published_at`. So the off-chain `gift_id` derivation must key
49
+ * on this, or it diverges from the on-chain `derive_gift_address` after
50
+ * the first upgrade. Falls back to `published_at` when `original_id` is
51
+ * absent (fresh deployments where the two are equal).
52
+ */
53
+ waterxPredictionGiftTypeOriginId(): string;
43
54
  waterxReferralPackageId(): string;
44
55
  referralTableId(): string;
45
56
  }
@@ -68,6 +68,22 @@ export class PredictClient extends BaseLineClient {
68
68
  claimableLinkConfigId() {
69
69
  return requireConfigValue(this.config.packages.waterx_prediction_gift, "claimable_link_config", "packages.waterx_prediction_gift.claimable_link_config");
70
70
  }
71
+ /**
72
+ * Original (first-published) id of the gift package. Used ONLY for the
73
+ * `GiftKey` type tag in derived-object address computation
74
+ * (`deriveGiftAddress`). Sui pins a struct's type identity to its
75
+ * defining package's *original* id — it never advances across upgrades,
76
+ * unlike `published_at`. So the off-chain `gift_id` derivation must key
77
+ * on this, or it diverges from the on-chain `derive_gift_address` after
78
+ * the first upgrade. Falls back to `published_at` when `original_id` is
79
+ * absent (fresh deployments where the two are equal).
80
+ */
81
+ waterxPredictionGiftTypeOriginId() {
82
+ const origin = this.config.packages.waterx_prediction_gift?.original_id;
83
+ return typeof origin === "string" && origin.length > 0
84
+ ? origin
85
+ : this.waterxPredictionGiftPackageId();
86
+ }
71
87
  waterxReferralPackageId() {
72
88
  return requireConfigValue(this.config.packages.waterx_referral, "published_at", "packages.waterx_referral.published_at");
73
89
  }
@@ -47,17 +47,12 @@ export interface WaterxPredictionConfig {
47
47
  }
48
48
  export interface LoadConfigOptions {
49
49
  /**
50
- * Override the default waterx-config raw JSON URL. Use this to point at a
51
- * local mirror during development. Takes precedence over {@link configRef}.
50
+ * Canonical `waterx-config` JSON URL to fetch, **as-is** (no `<network>.json`
51
+ * / git ref appended). Required {@link loadConfig} reads the URL only from
52
+ * this option (there is no env-var fallback and no built-in default) and
53
+ * throws when it is unset.
52
54
  */
53
- configUrl?: string;
54
- /**
55
- * Pin the canonical config to a specific git ref — a commit SHA, branch, or
56
- * tag — instead of the default `main` branch. Resolves to
57
- * `https://raw.githubusercontent.com/WaterXProtocol/waterx-config/<ref>/<network>.json`.
58
- * Ignored when {@link configUrl} is set.
59
- */
60
- configRef?: string;
55
+ waterxConfigUrl?: string;
61
56
  /** Reuse a previously fetched config in memory. Default: false. */
62
57
  cache?: boolean;
63
58
  /** Optional fetch implementation for tests or runtimes without global fetch. */
@@ -65,10 +60,5 @@ export interface LoadConfigOptions {
65
60
  /** Request timeout in ms. Default: 10_000. */
66
61
  timeoutMs?: number;
67
62
  }
68
- /**
69
- * Build the canonical config URL for `network`, optionally pinned to a
70
- * specific git `ref` (commit SHA, branch, or tag). Defaults to `main`.
71
- */
72
- export declare function defaultConfigUrl(network: Network, ref?: string): string;
73
63
  export declare function clearConfigCache(): void;
74
64
  export declare function loadConfig(network: Network, opts?: LoadConfigOptions): Promise<WaterxPredictionConfig>;
@@ -4,22 +4,15 @@
4
4
  * Mirrors the canonical `waterx-config` JSON for the packages used by this SDK
5
5
  * and fetches it from GitHub raw by default.
6
6
  */
7
- const CONFIG_REPO_RAW_BASE = "https://raw.githubusercontent.com/WaterXProtocol/waterx-config";
8
- /** Default git ref for the canonical config when none is pinned. */
9
- const DEFAULT_CONFIG_REF = "main";
10
- /**
11
- * Build the canonical config URL for `network`, optionally pinned to a
12
- * specific git `ref` (commit SHA, branch, or tag). Defaults to `main`.
13
- */
14
- export function defaultConfigUrl(network, ref = DEFAULT_CONFIG_REF) {
15
- return `${CONFIG_REPO_RAW_BASE}/${ref}/${network.toLowerCase()}.json`;
16
- }
17
7
  const configCache = new Map();
18
8
  export function clearConfigCache() {
19
9
  configCache.clear();
20
10
  }
21
11
  export async function loadConfig(network, opts = {}) {
22
- const url = opts.configUrl ?? defaultConfigUrl(network, opts.configRef);
12
+ const url = opts.waterxConfigUrl;
13
+ if (!url) {
14
+ throw new Error("loadConfig: no config URL — pass opts.waterxConfigUrl");
15
+ }
23
16
  if (opts.cache && configCache.has(url)) {
24
17
  return configCache.get(url);
25
18
  }
@@ -1,5 +1,5 @@
1
1
  import type { PredictClient } from "./client.ts";
2
- import type { AccountDataView, CursorView, MarketExposure, MarketIdInput, MarketView, OrderView, PositionView, RegistryView } from "./types.ts";
2
+ import type { AccountDataView, CursorView, MarketExposure, MarketIdInput, MarketPage, MarketView, OrderView, PageParams, PositionPage, PositionView, RegistryView } from "./types.ts";
3
3
  export declare function extractReturnBytes(result: any, commandIndex?: number, returnIndex?: number): Uint8Array;
4
4
  export interface ViewBaseParams {
5
5
  packageId?: string;
@@ -30,6 +30,11 @@ export declare function getOrderCursor(client: PredictClient, params?: ViewBaseP
30
30
  export declare function getPositionCursor(client: PredictClient, params?: ViewBaseParams): Promise<CursorView>;
31
31
  export declare function getUnresolvedMarketCursor(client: PredictClient, params?: ViewBaseParams): Promise<CursorView>;
32
32
  export declare function getResolvedMarketCursor(client: PredictClient, params?: ViewBaseParams): Promise<CursorView>;
33
+ /** Every unresolved (active) market in one call. Prefer `getUnresolvedMarketsPage` when the table is large. */
34
+ export declare function getUnresolvedMarkets(client: PredictClient, params?: ViewBaseParams): Promise<MarketView[]>;
35
+ export declare function getUnresolvedMarketsPage(client: PredictClient, params?: PageParams): Promise<MarketPage>;
36
+ export declare function getResolvedMarketsPage(client: PredictClient, params?: PageParams): Promise<MarketPage>;
37
+ export declare function getPositionsPage(client: PredictClient, params?: PageParams): Promise<PositionPage>;
33
38
  export interface GetAccountIdsParams {
34
39
  /** Wallet address that owns sub-accounts in the registry. */
35
40
  owner: string;
@@ -125,6 +125,66 @@ export function getUnresolvedMarketCursor(client, params = {}) {
125
125
  export function getResolvedMarketCursor(client, params = {}) {
126
126
  return readCursor(client, "resolved_market_cursor", params);
127
127
  }
128
+ const DEFAULT_PAGE_LIMIT = 100n;
129
+ /** Encode an optional cursor key as a Move `Option<u64>` pure arg (`undefined` → none / from front). */
130
+ function startArg(tx, start) {
131
+ return tx.pure(bcs.option(bcs.u64()).serialize(start === undefined ? null : toBigInt(start)));
132
+ }
133
+ /** Every unresolved (active) market in one call. Prefer `getUnresolvedMarketsPage` when the table is large. */
134
+ export async function getUnresolvedMarkets(client, params = {}) {
135
+ const tx = new Transaction();
136
+ tx.moveCall({
137
+ target: `${resolvePackageId(client, params.packageId)}::view::unresolved_markets`,
138
+ typeArguments: [resolveSettlementCoinType(client, params.settlementCoinType)],
139
+ arguments: [tx.object(resolveMarketRegistry(client, params.marketRegistry))],
140
+ });
141
+ const result = await client.simulate(tx);
142
+ return bcs.vector(MarketViewBcs).parse(extractReturnBytes(result)).map(mapMarketView);
143
+ }
144
+ async function readMarketsPage(client, functionName, params = {}) {
145
+ const tx = new Transaction();
146
+ tx.moveCall({
147
+ target: `${resolvePackageId(client, params.packageId)}::view::${functionName}`,
148
+ typeArguments: [resolveSettlementCoinType(client, params.settlementCoinType)],
149
+ arguments: [
150
+ tx.object(resolveMarketRegistry(client, params.marketRegistry)),
151
+ startArg(tx, params.start),
152
+ tx.pure.u64(params.limit === undefined ? DEFAULT_PAGE_LIMIT : toBigInt(params.limit)),
153
+ ],
154
+ });
155
+ const result = await client.simulate(tx);
156
+ const markets = bcs
157
+ .vector(MarketViewBcs)
158
+ .parse(extractReturnBytes(result, 0, 0))
159
+ .map(mapMarketView);
160
+ const next = bcs.option(bcs.u64()).parse(extractReturnBytes(result, 0, 1));
161
+ return { markets, nextCursor: next == null ? null : BigInt(next) };
162
+ }
163
+ export function getUnresolvedMarketsPage(client, params = {}) {
164
+ return readMarketsPage(client, "unresolved_markets_page", params);
165
+ }
166
+ export function getResolvedMarketsPage(client, params = {}) {
167
+ return readMarketsPage(client, "resolved_markets_page", params);
168
+ }
169
+ export async function getPositionsPage(client, params = {}) {
170
+ const tx = new Transaction();
171
+ tx.moveCall({
172
+ target: `${resolvePackageId(client, params.packageId)}::view::positions_page`,
173
+ typeArguments: [resolveSettlementCoinType(client, params.settlementCoinType)],
174
+ arguments: [
175
+ tx.object(resolveMarketRegistry(client, params.marketRegistry)),
176
+ startArg(tx, params.start),
177
+ tx.pure.u64(params.limit === undefined ? DEFAULT_PAGE_LIMIT : toBigInt(params.limit)),
178
+ ],
179
+ });
180
+ const result = await client.simulate(tx);
181
+ const positions = bcs
182
+ .vector(PositionViewBcs)
183
+ .parse(extractReturnBytes(result, 0, 0))
184
+ .map(mapPositionView);
185
+ const next = bcs.option(bcs.u64()).parse(extractReturnBytes(result, 0, 1));
186
+ return { positions, nextCursor: next == null ? null : BigInt(next) };
187
+ }
128
188
  /**
129
189
  * Registry account ids (`0x2::object::ID`) for an owner via `waterx_account::account::account_ids`.
130
190
  * Use these ids with `getAccountData`, `deposit`, and `placeOrder` — not Suiscan "Account" object addresses.
@@ -25,6 +25,16 @@ import type { AccountIdentityParams, IdArgument, Selection } from "./types.ts";
25
25
  export interface GiftBaseParams {
26
26
  /** `waterx_prediction_gift` package id. Defaults to `client.waterxPredictionGiftPackageId()`. */
27
27
  giftPackageId?: string;
28
+ /**
29
+ * `waterx_prediction_gift` *original* (first-published) package id, used
30
+ * ONLY for the `GiftKey` type tag in {@link deriveGiftAddress}. Defaults to
31
+ * `client.waterxPredictionGiftTypeOriginId()` (config `original_id`, falling
32
+ * back to `giftPackageId`/`published_at`). Distinct from `giftPackageId`,
33
+ * which selects the *runtime* package for moveCall targets — after a package
34
+ * upgrade the two diverge, and only the original id reproduces the on-chain
35
+ * `gift_id`. Override only for offline derivation against a custom deploy.
36
+ */
37
+ giftTypeOriginId?: string;
28
38
  /** `ClaimableLinkConfig` object id. Defaults to `client.claimableLinkConfigId()`. */
29
39
  claimableLinkConfig?: string;
30
40
  /** Collateral / settlement coin type for the position's `Gift<T>`. Defaults to `client.settlementCoinType()`. */
@@ -72,6 +82,15 @@ export declare function signGiftClaim(giftKeypair: Ed25519Keypair, giftId: strin
72
82
  /**
73
83
  * Compute the `gift_id` that `create_gift` will produce for the given
74
84
  * pubkey, offline. No RPC. Mirrors `claimable_link::derive_gift_address`.
85
+ *
86
+ * The `GiftKey` type tag is keyed on the gift package's *original* id
87
+ * (via {@link resolveGiftTypeOriginId}), NOT `published_at`. On Sui a
88
+ * struct's type identity stays pinned to its defining package's original
89
+ * id and never advances across upgrades, so `derive_gift_address`
90
+ * hashes `GiftKey` under that original id. Using `published_at` here would
91
+ * silently diverge from the chain after the first package upgrade, yielding
92
+ * the wrong `gift_id` for every gift. The moveCall targets elsewhere in
93
+ * this module correctly stay on `published_at` (latest code).
75
94
  */
76
95
  export declare function deriveGiftAddress(client: PredictClient, pubkey: Uint8Array, params?: GiftBaseParams): string;
77
96
  export interface CreateGiftParams extends GiftBaseParams, GiftReferralParams, AccountIdentityParams {
@@ -32,6 +32,22 @@ function resolveGiftPackageId(client, override) {
32
32
  ? client.waterxPredictionGiftPackageId()
33
33
  : override;
34
34
  }
35
+ /**
36
+ * Resolve the package id for the `GiftKey` type tag in
37
+ * {@link deriveGiftAddress}. Precedence: explicit `giftTypeOriginId`, then
38
+ * the runtime `giftPackageId` override (a self-contained deploy where
39
+ * original == published), then the client's config `original_id` (falling
40
+ * back to `published_at`). This must key on the *original* id so the
41
+ * off-chain derivation matches the on-chain type identity, which never
42
+ * advances across package upgrades.
43
+ */
44
+ function resolveGiftTypeOriginId(client, originOverride, pkgOverride) {
45
+ if (originOverride !== undefined && originOverride !== "")
46
+ return originOverride;
47
+ if (pkgOverride !== undefined && pkgOverride !== "")
48
+ return pkgOverride;
49
+ return client.waterxPredictionGiftTypeOriginId();
50
+ }
35
51
  function resolveClaimableLinkConfig(client, override) {
36
52
  return override === undefined || override === "" ? client.claimableLinkConfigId() : override;
37
53
  }
@@ -145,12 +161,21 @@ const GiftKeyBcs = bcs.struct("GiftKey", {
145
161
  /**
146
162
  * Compute the `gift_id` that `create_gift` will produce for the given
147
163
  * pubkey, offline. No RPC. Mirrors `claimable_link::derive_gift_address`.
164
+ *
165
+ * The `GiftKey` type tag is keyed on the gift package's *original* id
166
+ * (via {@link resolveGiftTypeOriginId}), NOT `published_at`. On Sui a
167
+ * struct's type identity stays pinned to its defining package's original
168
+ * id and never advances across upgrades, so `derive_gift_address`
169
+ * hashes `GiftKey` under that original id. Using `published_at` here would
170
+ * silently diverge from the chain after the first package upgrade, yielding
171
+ * the wrong `gift_id` for every gift. The moveCall targets elsewhere in
172
+ * this module correctly stay on `published_at` (latest code).
148
173
  */
149
174
  export function deriveGiftAddress(client, pubkey, params = {}) {
150
175
  if (pubkey.length !== GIFT_PUBKEY_LEN) {
151
176
  throw new Error(`Gift pubkey must be ${GIFT_PUBKEY_LEN} bytes, got ${pubkey.length}`);
152
177
  }
153
- const giftPkg = resolveGiftPackageId(client, params.giftPackageId);
178
+ const giftPkg = resolveGiftTypeOriginId(client, params.giftTypeOriginId, params.giftPackageId);
154
179
  const configId = resolveClaimableLinkConfig(client, params.claimableLinkConfig);
155
180
  const keyBytes = GiftKeyBcs.serialize({ pubkey: Array.from(pubkey) }).toBytes();
156
181
  return deriveObjectID(configId, `${giftPkg}::claimable_link::GiftKey`, keyBytes);
@@ -1,6 +1,6 @@
1
1
  export { PredictClient } from "./client.ts";
2
2
  export type { CreateClientOptions } from "./client.ts";
3
- export { clearConfigCache, defaultConfigUrl, loadConfig } from "./config.ts";
3
+ export { clearConfigCache, loadConfig } from "./config.ts";
4
4
  export type { LoadConfigOptions, WaterxAccountPackage, WaterxConfigPackageBase, WaterxPredictionConfig, WaterxPredictionConfigPackages, WaterxPredictionGiftPackage, WaterxPredictionPackage, WaterxReferralPackage, } from "./config.ts";
5
5
  export * from "./constants.ts";
6
6
  export * from "./types.ts";
@@ -14,7 +14,7 @@ export { adminPlaceOrderFor, batchClaim, batchForceClaim, buildBatchForceClaimTr
14
14
  export type { AdminPlaceOrderForParams, BatchClaimParams, BatchForceClaimParams, BuildBatchForceClaimTransactionsParams, CancelCloseParams, CancelOrderParams, ClaimParams, ConfirmCloseParams, FillOrderParams, ForceClaimParams, PlaceOrderParams, RequestCloseParams, RequestPartialCloseParams, ResolveMarketParams, SelfCancelCloseParams, SelfCancelOrderParams, SplitPositionParams, TransferPositionParams, } from "./prediction.ts";
15
15
  export { buildBatchClaimTx, buildPlaceOrderTx } from "./tx-builders.ts";
16
16
  export type { BuildBatchClaimTxParams, BuildPlaceOrderTxParams, PredictCommonBuildOpts, } from "./tx-builders.ts";
17
- export { getAccountData, getAccountIds, getAccountOrderIds, getAccountOrderIdsByMarketId, getAccountPositionIds, getAccountPositionIdsByMarketId, getKeeperAddresses, getAllowedVersions, getMarketExposure, getMarketExposureByKey, getMarketById, getMarketByKey, getOrder, getOrderCursor, getPosition, getPositionCursor, getRegistry, getResolvedMarketCursor, getUnresolvedMarketCursor, isKeeper, isPredictionProtocolAssetAllowed, } from "./fetch.ts";
17
+ export { getAccountData, getAccountIds, getAccountOrderIds, getAccountOrderIdsByMarketId, getAccountPositionIds, getAccountPositionIdsByMarketId, getKeeperAddresses, getAllowedVersions, getMarketExposure, getMarketExposureByKey, getMarketById, getMarketByKey, getOrder, getOrderCursor, getPosition, getPositionCursor, getPositionsPage, getRegistry, getResolvedMarketCursor, getResolvedMarketsPage, getUnresolvedMarketCursor, getUnresolvedMarkets, getUnresolvedMarketsPage, isKeeper, isPredictionProtocolAssetAllowed, } from "./fetch.ts";
18
18
  export type { GetAccountIdsParams, ViewBaseParams } from "./fetch.ts";
19
19
  export { base64UrlNoPadDecode, base64UrlNoPadEncode, buildClaimShareFlow, buildCreateGiftFlow, buildGiftClaimMessage, claimShare, createGift, deleteGift, deriveGiftAddress, deriveGiftKeypair, encodeGiftUrl, generateGiftSeed, getCreatorGiftCount, getCreatorGiftIds, getGift, getGiftConfigPaused, getGiftControllerAddress, getGiftHasClaimed, parseGiftUrl, signGiftClaim, } from "./gift.ts";
20
20
  export type { BuildClaimShareFlowParams, BuildClaimShareFlowResult, BuildCreateGiftFlowResult, ClaimShareParams, CreateGiftParams, DeleteGiftParams, GiftBaseParams, GiftReferralParams, GiftUrlParts, GiftView, } from "./gift.ts";
@@ -1,5 +1,5 @@
1
1
  export { PredictClient } from "./client.js";
2
- export { clearConfigCache, defaultConfigUrl, loadConfig } from "./config.js";
2
+ export { clearConfigCache, loadConfig } from "./config.js";
3
3
  export * from "./constants.js";
4
4
  export * from "./types.js";
5
5
  export * as user from "./user/index.js";
@@ -8,7 +8,7 @@ export { addDelegate, allowPredictionProtocolAsset, consumeDepositDirect, consum
8
8
  export { addKeeper, adminWithdraw, createMarketRegistry, depositSettlement, pauseMarket, removeKeeper, setMinReserve, setOrderCancelCooldownMs, unpauseMarket, } from "./admin.js";
9
9
  export { adminPlaceOrderFor, batchClaim, batchForceClaim, buildBatchForceClaimTransactions, cancelClose, cancelOrder, claim, confirmClose, fillOrder, forceClaim, outcomeArg, placeOrder, requestClose, requestPartialClose, resolveMarket, selectionArg, selfCancelClose, selfCancelOrder, splitPosition, transferPosition, } from "./prediction.js";
10
10
  export { buildBatchClaimTx, buildPlaceOrderTx } from "./tx-builders.js";
11
- export { getAccountData, getAccountIds, getAccountOrderIds, getAccountOrderIdsByMarketId, getAccountPositionIds, getAccountPositionIdsByMarketId, getKeeperAddresses, getAllowedVersions, getMarketExposure, getMarketExposureByKey, getMarketById, getMarketByKey, getOrder, getOrderCursor, getPosition, getPositionCursor, getRegistry, getResolvedMarketCursor, getUnresolvedMarketCursor, isKeeper, isPredictionProtocolAssetAllowed, } from "./fetch.js";
11
+ export { getAccountData, getAccountIds, getAccountOrderIds, getAccountOrderIdsByMarketId, getAccountPositionIds, getAccountPositionIdsByMarketId, getKeeperAddresses, getAllowedVersions, getMarketExposure, getMarketExposureByKey, getMarketById, getMarketByKey, getOrder, getOrderCursor, getPosition, getPositionCursor, getPositionsPage, getRegistry, getResolvedMarketCursor, getResolvedMarketsPage, getUnresolvedMarketCursor, getUnresolvedMarkets, getUnresolvedMarketsPage, isKeeper, isPredictionProtocolAssetAllowed, } from "./fetch.js";
12
12
  export { base64UrlNoPadDecode, base64UrlNoPadEncode, buildClaimShareFlow, buildCreateGiftFlow, buildGiftClaimMessage, claimShare, createGift, deleteGift, deriveGiftAddress, deriveGiftKeypair, encodeGiftUrl, generateGiftSeed, getCreatorGiftCount, getCreatorGiftIds, getGift, getGiftConfigPaused, getGiftControllerAddress, getGiftHasClaimed, parseGiftUrl, signGiftClaim, } from "./gift.js";
13
13
  export * as bucketFrameworkAccountCalls from "../generated/bucket_v2_framework/account.js";
14
14
  export * as waterxAccountCalls from "../generated/waterx_account/account.js";
@@ -88,6 +88,25 @@ export interface CursorView {
88
88
  front: bigint | null;
89
89
  back: bigint | null;
90
90
  }
91
+ export interface PageParams {
92
+ packageId?: string;
93
+ marketRegistry?: string;
94
+ settlementCoinType?: string;
95
+ /** Cursor key to resume from; omit to start at the front of the table. */
96
+ start?: bigint | number | string;
97
+ /** Max entries in this page (default 100). */
98
+ limit?: bigint | number | string;
99
+ }
100
+ export interface MarketPage {
101
+ markets: MarketView[];
102
+ /** Pass as `start` for the next page; `null` when the table is exhausted. */
103
+ nextCursor: bigint | null;
104
+ }
105
+ export interface PositionPage {
106
+ positions: PositionView[];
107
+ /** Pass as `start` for the next page; `null` when the table is exhausted. */
108
+ nextCursor: bigint | null;
109
+ }
91
110
  export interface CoinRef {
92
111
  objectId: string;
93
112
  version: string | bigint | number;
@@ -263,6 +263,10 @@ declare const predictOps: {
263
263
  getPositionCursor(client: PredictClient, params?: predFetch.ViewBaseParams): Promise<import("./prediction/types.ts").CursorView>;
264
264
  getUnresolvedMarketCursor(client: PredictClient, params?: predFetch.ViewBaseParams): Promise<import("./prediction/types.ts").CursorView>;
265
265
  getResolvedMarketCursor(client: PredictClient, params?: predFetch.ViewBaseParams): Promise<import("./prediction/types.ts").CursorView>;
266
+ getUnresolvedMarkets(client: PredictClient, params?: predFetch.ViewBaseParams): Promise<import("./prediction/types.ts").MarketView[]>;
267
+ getUnresolvedMarketsPage(client: PredictClient, params?: import("./prediction/types.ts").PageParams): Promise<import("./prediction/types.ts").MarketPage>;
268
+ getResolvedMarketsPage(client: PredictClient, params?: import("./prediction/types.ts").PageParams): Promise<import("./prediction/types.ts").MarketPage>;
269
+ getPositionsPage(client: PredictClient, params?: import("./prediction/types.ts").PageParams): Promise<import("./prediction/types.ts").PositionPage>;
266
270
  getAccountIds(client: PredictClient, params: predFetch.GetAccountIdsParams): Promise<string[]>;
267
271
  getAccountData(client: PredictClient, params: predFetch.ViewBaseParams & {
268
272
  accountId: string;
@@ -354,13 +358,14 @@ export interface ClientCreateOptions {
354
358
  network?: Network;
355
359
  /** Default gRPC URL for both lines. */
356
360
  grpcUrl?: string;
357
- /** Default `waterx-config` JSON URL for both lines. */
358
- configUrl?: string;
361
+ /** Default `waterx-config` JSON URL for both lines (fetched as-is). Required
362
+ * unless supplied per-line via `perp` / `predict`. */
363
+ waterxConfigUrl?: string;
359
364
  /** Memoize the fetched config JSON. */
360
365
  cache?: boolean;
361
- /** Perp-line overrides (network, grpcUrl, configUrl, cache, …). */
366
+ /** Perp-line overrides (network, grpcUrl, waterxConfigUrl, cache, …). */
362
367
  perp?: PerpLineOptions;
363
- /** Prediction-line overrides (network, grpcUrl, configUrl, cache, settlement, …). */
368
+ /** Prediction-line overrides (network, grpcUrl, waterxConfigUrl, cache, settlement, …). */
364
369
  predict?: PredictLineOptions;
365
370
  }
366
371
  export declare class WaterXClient {
@@ -166,13 +166,13 @@ export class WaterXClient {
166
166
  }
167
167
  const perpClient = await PerpClient.create(resolvedPerpNetwork, {
168
168
  grpcUrl: opts.grpcUrl,
169
- configUrl: opts.configUrl,
169
+ waterxConfigUrl: opts.waterxConfigUrl,
170
170
  cache: opts.cache,
171
171
  ...perpRest,
172
172
  });
173
173
  const predictClient = await PredictClient.create(resolvedPredictNetwork, {
174
174
  grpcUrl: opts.grpcUrl,
175
- configUrl: opts.configUrl,
175
+ waterxConfigUrl: opts.waterxConfigUrl,
176
176
  cache: opts.cache,
177
177
  ...predictRest,
178
178
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waterx/sdk",
3
- "version": "3.0.3",
3
+ "version": "3.1.1",
4
4
  "description": "WaterX SDK — perpetuals and prediction markets on Sui",
5
5
  "license": "MIT",
6
6
  "author": "WaterX",