@waterx/sdk 3.1.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/README.md +53 -7
  2. package/dist/cjs/src/oracle/aggregate.d.ts +98 -17
  3. package/dist/cjs/src/oracle/aggregate.js +191 -21
  4. package/dist/cjs/src/oracle/config.d.ts +103 -0
  5. package/dist/cjs/src/oracle/config.js +64 -1
  6. package/dist/cjs/src/oracle/host.d.ts +13 -0
  7. package/dist/cjs/src/oracle/index.d.ts +19 -5
  8. package/dist/cjs/src/oracle/index.js +40 -6
  9. package/dist/cjs/src/oracle/price-update-rule.d.ts +180 -0
  10. package/dist/cjs/src/oracle/price-update-rule.js +56 -0
  11. package/dist/cjs/src/oracle/pyth.d.ts +80 -11
  12. package/dist/cjs/src/oracle/pyth.js +84 -17
  13. package/dist/cjs/src/oracle/rule-registry.d.ts +37 -0
  14. package/dist/cjs/src/oracle/rule-registry.js +61 -0
  15. package/dist/cjs/src/oracle/rules/pyth-core-rule.d.ts +15 -0
  16. package/dist/cjs/src/oracle/rules/pyth-core-rule.js +84 -0
  17. package/dist/cjs/src/oracle/rules/pyth-lazer-rule.d.ts +41 -0
  18. package/dist/cjs/src/oracle/rules/pyth-lazer-rule.js +194 -0
  19. package/dist/cjs/src/oracle/rules/sponsor.d.ts +11 -7
  20. package/dist/cjs/src/oracle/rules/sponsor.js +11 -7
  21. package/dist/cjs/src/oracle/update-fetch.d.ts +85 -0
  22. package/dist/cjs/src/oracle/update-fetch.js +228 -0
  23. package/dist/cjs/src/perp/client.d.ts +22 -1
  24. package/dist/cjs/src/perp/client.js +11 -2
  25. package/dist/cjs/src/perp/config.d.ts +15 -20
  26. package/dist/cjs/src/perp/config.js +86 -30
  27. package/dist/cjs/src/perp/index.d.ts +4 -3
  28. package/dist/cjs/src/perp/index.js +8 -4
  29. package/dist/cjs/src/perp/tx-builders/common.d.ts +52 -15
  30. package/dist/cjs/src/perp/tx-builders/common.js +39 -6
  31. package/dist/cjs/src/perp/tx-builders/wlp.d.ts +11 -3
  32. package/dist/cjs/src/perp/tx-builders/wlp.js +29 -3
  33. package/dist/cjs/src/perp/tx-builders.d.ts +3 -3
  34. package/dist/cjs/src/perp/tx-builders.js +3 -3
  35. package/dist/cjs/src/prediction/config.d.ts +5 -15
  36. package/dist/cjs/src/prediction/config.js +4 -12
  37. package/dist/cjs/src/prediction/fetch.d.ts +6 -1
  38. package/dist/cjs/src/prediction/fetch.js +64 -0
  39. package/dist/cjs/src/prediction/index.d.ts +2 -2
  40. package/dist/cjs/src/prediction/index.js +7 -4
  41. package/dist/cjs/src/prediction/types.d.ts +19 -0
  42. package/dist/cjs/src/unified-client.d.ts +26 -4
  43. package/dist/cjs/src/unified-client.js +4 -2
  44. package/dist/src/oracle/aggregate.d.ts +98 -17
  45. package/dist/src/oracle/aggregate.js +192 -22
  46. package/dist/src/oracle/config.d.ts +103 -0
  47. package/dist/src/oracle/config.js +63 -0
  48. package/dist/src/oracle/host.d.ts +13 -0
  49. package/dist/src/oracle/index.d.ts +19 -5
  50. package/dist/src/oracle/index.js +34 -6
  51. package/dist/src/oracle/price-update-rule.d.ts +180 -0
  52. package/dist/src/oracle/price-update-rule.js +53 -0
  53. package/dist/src/oracle/pyth.d.ts +80 -11
  54. package/dist/src/oracle/pyth.js +82 -16
  55. package/dist/src/oracle/rule-registry.d.ts +37 -0
  56. package/dist/src/oracle/rule-registry.js +56 -0
  57. package/dist/src/oracle/rules/pyth-core-rule.d.ts +15 -0
  58. package/dist/src/oracle/rules/pyth-core-rule.js +81 -0
  59. package/dist/src/oracle/rules/pyth-lazer-rule.d.ts +41 -0
  60. package/dist/src/oracle/rules/pyth-lazer-rule.js +189 -0
  61. package/dist/src/oracle/rules/sponsor.d.ts +11 -7
  62. package/dist/src/oracle/rules/sponsor.js +11 -7
  63. package/dist/src/oracle/update-fetch.d.ts +85 -0
  64. package/dist/src/oracle/update-fetch.js +223 -0
  65. package/dist/src/perp/client.d.ts +22 -1
  66. package/dist/src/perp/client.js +12 -3
  67. package/dist/src/perp/config.d.ts +15 -20
  68. package/dist/src/perp/config.js +85 -29
  69. package/dist/src/perp/index.d.ts +4 -3
  70. package/dist/src/perp/index.js +2 -2
  71. package/dist/src/perp/tx-builders/common.d.ts +52 -15
  72. package/dist/src/perp/tx-builders/common.js +39 -6
  73. package/dist/src/perp/tx-builders/wlp.d.ts +11 -3
  74. package/dist/src/perp/tx-builders/wlp.js +29 -3
  75. package/dist/src/perp/tx-builders.d.ts +3 -3
  76. package/dist/src/perp/tx-builders.js +3 -3
  77. package/dist/src/prediction/config.d.ts +5 -15
  78. package/dist/src/prediction/config.js +4 -11
  79. package/dist/src/prediction/fetch.d.ts +6 -1
  80. package/dist/src/prediction/fetch.js +60 -0
  81. package/dist/src/prediction/index.d.ts +2 -2
  82. package/dist/src/prediction/index.js +2 -2
  83. package/dist/src/prediction/types.d.ts +19 -0
  84. package/dist/src/unified-client.d.ts +26 -4
  85. package/dist/src/unified-client.js +4 -2
  86. package/package.json +1 -1
@@ -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.
@@ -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;
@@ -32,6 +32,8 @@ import { Transaction } from "@mysten/sui/transactions";
32
32
  import * as accountOps from "./account/index.ts";
33
33
  import * as perpReferral from "./account/referral.ts";
34
34
  import type { Network } from "./constants.ts";
35
+ import type { PythGeneration } from "./oracle/config.ts";
36
+ import type { OracleSource } from "./oracle/price-update-rule.ts";
35
37
  import { PerpClient, type CreateClientOptions as PerpCreateOptions } from "./perp/client.ts";
36
38
  import * as perpFetch from "./perp/fetch.ts";
37
39
  import * as perpTx from "./perp/tx-builders.ts";
@@ -263,6 +265,10 @@ declare const predictOps: {
263
265
  getPositionCursor(client: PredictClient, params?: predFetch.ViewBaseParams): Promise<import("./prediction/types.ts").CursorView>;
264
266
  getUnresolvedMarketCursor(client: PredictClient, params?: predFetch.ViewBaseParams): Promise<import("./prediction/types.ts").CursorView>;
265
267
  getResolvedMarketCursor(client: PredictClient, params?: predFetch.ViewBaseParams): Promise<import("./prediction/types.ts").CursorView>;
268
+ getUnresolvedMarkets(client: PredictClient, params?: predFetch.ViewBaseParams): Promise<import("./prediction/types.ts").MarketView[]>;
269
+ getUnresolvedMarketsPage(client: PredictClient, params?: import("./prediction/types.ts").PageParams): Promise<import("./prediction/types.ts").MarketPage>;
270
+ getResolvedMarketsPage(client: PredictClient, params?: import("./prediction/types.ts").PageParams): Promise<import("./prediction/types.ts").MarketPage>;
271
+ getPositionsPage(client: PredictClient, params?: import("./prediction/types.ts").PageParams): Promise<import("./prediction/types.ts").PositionPage>;
266
272
  getAccountIds(client: PredictClient, params: predFetch.GetAccountIdsParams): Promise<string[]>;
267
273
  getAccountData(client: PredictClient, params: predFetch.ViewBaseParams & {
268
274
  accountId: string;
@@ -354,13 +360,29 @@ export interface ClientCreateOptions {
354
360
  network?: Network;
355
361
  /** Default gRPC URL for both lines. */
356
362
  grpcUrl?: string;
357
- /** Default `waterx-config` JSON URL for both lines. */
358
- configUrl?: string;
363
+ /** Default `waterx-config` JSON URL for both lines (fetched as-is). Required
364
+ * unless supplied per-line via `perp` / `predict`. */
365
+ waterxConfigUrl?: string;
359
366
  /** Memoize the fetched config JSON. */
360
367
  cache?: boolean;
361
- /** Perp-line overrides (network, grpcUrl, configUrl, cache, …). */
368
+ /**
369
+ * Selects which `PriceUpdateRule` the perp line's `refreshOraclePrices` uses
370
+ * for the on-chain price-update leg (see `OracleHost.oracleSource`).
371
+ * Default: `'pyth_rule'`. Perp-line only. The SDK never reads `process.env`
372
+ * — pass this from your own env var (e.g. `ORACLE_SOURCE`).
373
+ */
374
+ oracleSource?: OracleSource;
375
+ /**
376
+ * Selects which Pyth Core contract generation feeds the perp line's
377
+ * `client.perp.pyth` when the config JSON has no explicit `pyth` override:
378
+ * `'core'` (default) or `'pro'` (post-2026-08-18 Pro-compatible contracts +
379
+ * Hermes-compatible endpoint; pair with `pyth.api_key`). Perp-line only.
380
+ * See `PythGeneration` / `PYTH_PRO_DEFAULTS`.
381
+ */
382
+ pythGeneration?: PythGeneration;
383
+ /** Perp-line overrides (network, grpcUrl, waterxConfigUrl, cache, …). */
362
384
  perp?: PerpLineOptions;
363
- /** Prediction-line overrides (network, grpcUrl, configUrl, cache, settlement, …). */
385
+ /** Prediction-line overrides (network, grpcUrl, waterxConfigUrl, cache, settlement, …). */
364
386
  predict?: PredictLineOptions;
365
387
  }
366
388
  export declare class WaterXClient {
@@ -202,13 +202,15 @@ 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
+ oracleSource: opts.oracleSource,
208
+ pythGeneration: opts.pythGeneration,
207
209
  ...perpRest,
208
210
  });
209
211
  const predictClient = await client_ts_2.PredictClient.create(resolvedPredictNetwork, {
210
212
  grpcUrl: opts.grpcUrl,
211
- configUrl: opts.configUrl,
213
+ waterxConfigUrl: opts.waterxConfigUrl,
212
214
  cache: opts.cache,
213
215
  ...predictRest,
214
216
  });
@@ -2,40 +2,58 @@
2
2
  * Oracle aggregation — the orchestrator that composes rules into the shared
3
3
  * `Oracle`. This is the ONE file that knows about every rule: it builds a
4
4
  * `PriceCollector`, feeds whichever rules a ticker is configured for
5
- * (Pyth / Supra / Constant), then `aggregate`s.
5
+ * (Pyth / Lazer / Supra / Constant), then `aggregate`s.
6
6
  *
7
7
  * Per ticker:
8
8
  * collector = oracle::new_collector(ticker)
9
9
  * [pyth_rule::feed] when the ticker has a pyth_rule.feeds entry
10
+ * [pyth_lazer_rule::feed] when the update leg produced a verified lazer Update
10
11
  * [supra_rule::feed] when supra is enabled + wired
11
12
  * [constant_rule::feed] when the ticker is a constant ticker
12
13
  * oracle::aggregate(oracle, collector)
13
14
  *
14
- * The fed rule set must match the on-chain weighted set for the ticker —
15
+ * The fed rule set must cover the on-chain weighted set for the ticker —
15
16
  * `aggregator::remove_outliers` aborts `EMissingPriceSource` if a weighted rule
16
- * is missing from the collector.
17
+ * is missing from the collector (an abstaining feed call counts as present;
18
+ * a fed-but-unweighted rule is silently dropped).
19
+ *
20
+ * `refreshOraclePrices` additionally routes the on-chain price *update* leg
21
+ * (the fetch + verify/push step, before any of the above feeding) through the
22
+ * `PriceUpdateRule` selected by `host.oracleSource` — see `rule-registry.ts`.
17
23
  */
18
24
  import type { Transaction, TransactionArgument } from "@mysten/sui/transactions";
19
25
  import type { OracleHost } from "./host.ts";
20
- import { type PythCache } from "./pyth.ts";
26
+ import type { OracleSource, PriceUpdateRule, UpdateDataProvider } from "./price-update-rule.ts";
27
+ import { type OracleFeeSource, type PythCache } from "./pyth.ts";
21
28
  /**
22
29
  * Aggregate one ticker's price into the shared `Oracle`: build a collector, feed
23
30
  * every rule the ticker is configured for, then `aggregate`.
24
31
  *
25
32
  * - **Pyth** — fed when `priceInfoObjectId` is supplied (i.e. the ticker has a
26
- * `pyth_rule.feeds` entry). Caller must run the Pyth update first so the
27
- * `PriceInfoObject` is fresh.
28
- * - **Supra** fed alongside Pyth when supra is enabled + wired (abstains
29
- * on-chain for symbols it has no pair for).
33
+ * `pyth_rule.feeds` entry). When this PTB's update leg refreshed the
34
+ * `PriceInfoObject` it contributes a fresh price; when it did not (a
35
+ * lazer-routed ticker), the on-chain rule only READS the object and abstains
36
+ * if it is stale — it never aborts so the call stays mandatory while
37
+ * `pyth_rule` remains in the ticker's on-chain weighted set
38
+ * (`EMissingPriceSource` requires every weighted rule to appear).
39
+ * - **Lazer** — fed when `lazerUpdate` is supplied: the verified
40
+ * `pyth_lazer::update::Update` produced by this PTB's lazer update leg
41
+ * (see `PythLazerRule.buildUpdateCalls`). If the ticker's aggregator does
42
+ * not (yet) weight `PythLazerRule`, the contribution is silently dropped
43
+ * on-chain — feeding ahead of the weight migration is harmless.
44
+ * - **Supra** — fed alongside Pyth/Lazer when supra is enabled + wired
45
+ * (abstains on-chain for symbols it has no pair for).
30
46
  * - **Constant** — fed when the ticker is a constant ticker
31
47
  * ({@link OracleHost.isConstantTicker}).
32
48
  *
33
- * "Dual-feed" (Pyth + Constant) and "constant-only" are not special cases — they
34
- * fall out of which rules the ticker is in. Throws if no rule applies.
49
+ * "Dual-feed" (Pyth + Constant, or Pyth + Lazer) and "constant-only" are not
50
+ * special cases — they fall out of which rules the ticker is in. Throws if no
51
+ * rule applies.
35
52
  */
36
53
  export declare function aggregateTicker(tx: Transaction, host: OracleHost, args: {
37
54
  ticker: string;
38
55
  priceInfoObjectId?: string;
56
+ lazerUpdate?: TransactionArgument;
39
57
  }): void;
40
58
  /**
41
59
  * Thin wrapper over {@link aggregateTicker} for a Pyth-fed ticker. Kept for
@@ -61,14 +79,77 @@ export declare function aggregateTickerWithConstant(tx: Transaction, host: Oracl
61
79
  /**
62
80
  * Refresh multiple tickers in one PTB. For each ticker {@link aggregateTicker}
63
81
  * feeds whichever rules it is configured for (Pyth if it has a `pyth_rule.feeds`
64
- * entry, Supra when enabled, Constant when it's a constant ticker). Tickers with a
65
- * Pyth feed are updated on-chain via one shared Pyth accumulator first; the rest
66
- * (constant-only) skip Pyth entirely.
82
+ * entry, Lazer if the lazer update leg served it see below Supra when
83
+ * enabled, Constant when it's a constant ticker).
84
+ *
85
+ * Before that, the on-chain price *update* leg is routed by `host.oracleSource`
86
+ * (see `rule-registry.ts`): the selected rule serves every ticker in its
87
+ * `supportedTickers(host)`; tickers it doesn't cover fall back to `pyth_rule`
88
+ * (`PythCoreRule`) when THEY support it — so when `oracleSource` IS `'pyth_rule'`
89
+ * there is exactly one group, identical to the pre-routing behavior. A ticker
90
+ * supported by neither is simply skipped from this leg (no fetch/build call for
91
+ * it) — the same way today's non-pyth tickers (e.g. constant-only) always were;
92
+ * it still gets aggregated below via whichever rule {@link aggregateTicker} finds.
93
+ *
94
+ * Each group's fetch + build runs against its own rule, which guarantees
95
+ * per-rule PTB atomicity (no mixed-generation payload within one rule's calls).
96
+ * When `oracleSource` isn't `'pyth_rule'`, one PTB may legitimately carry BOTH a
97
+ * non-Pyth-Core block (selected group) and a Pyth Core block (fallback group) —
98
+ * each verifies against its own contract objects, so that's fine. A fee-source
99
+ * pre-check runs first, across every group's `requiresFeeSource` — BEFORE any
100
+ * off-chain fetch or PTB mutation — so a fee-charging group with no
101
+ * `opts.feeSource` throws `OracleFeeSourceUnavailable` with zero wasted
102
+ * network calls and zero stray moveCalls, even in a mixed shape (e.g. a
103
+ * fee-free Lazer group ordered ahead of a Pyth Core fallback group). Only once
104
+ * that check passes do all groups' off-chain fetches run concurrently
105
+ * (`Promise.all`) and complete before any PTB mutation; on-chain reads inside
106
+ * `buildUpdateCalls` can still fail mid-append for other reasons — callers
107
+ * discard the tx on any throw.
108
+ *
109
+ * **Collector-feed leg is rule-aware:** a lazer-served group's
110
+ * `buildUpdateCalls` returns the verified `Update` PTB value
111
+ * ({@link RuleUpdateHandle}), and every ticker in that group is aggregated
112
+ * with `lazerUpdate` set so {@link aggregateTicker} appends
113
+ * `pyth_lazer_rule::feed` against it. A lazer-routed ticker that still has a
114
+ * `pyth_rule.feeds` entry ALSO keeps its `pyth_rule::feed` leg — required
115
+ * on-chain while `pyth_rule` stays in the ticker's weighted set
116
+ * (`aggregator::remove_outliers` aborts `EMissingPriceSource` unless every
117
+ * weighted rule appears in the collector; an abstention counts as
118
+ * appearing), and safe: `pyth_rule::feed` only READS the `PriceInfoObject`
119
+ * this PTB never refreshed and abstains when it is stale rather than
120
+ * aborting. Conversely, a lazer feed call on an aggregator that does not
121
+ * (yet) weight `PythLazerRule` is silently dropped on-chain — so
122
+ * lazer-routing a ticker ahead of its on-chain weight migration prices it
123
+ * from the remaining weighted rules instead of failing.
67
124
  */
68
125
  export declare function refreshOraclePrices(tx: Transaction, host: OracleHost, tickers: string[], opts?: {
69
126
  cache?: PythCache;
70
- sponsorFund?: {
71
- fund: TransactionArgument;
72
- packageId: string;
73
- };
127
+ /**
128
+ * The single resolved fee source for the Pyth update fee, forwarded
129
+ * verbatim to each group's `PriceUpdateRule.buildUpdateCalls` as
130
+ * `BuildUpdateOpts.feeSource`. Already-resolved by the caller (see
131
+ * {@link OracleFeeSource}'s own doc for where/how) — this function makes
132
+ * no sponsor-vs-gas decision itself, it only checks whether a source was
133
+ * resolved at all. Ignored by rules with no update fee (e.g.
134
+ * `pyth_lazer_rule`). Building with `feeSource` unset throws
135
+ * `OracleFeeSourceUnavailable` (see `oracle/pyth.ts`) instead of
136
+ * silently drawing from `tx.gas`.
137
+ */
138
+ feeSource?: OracleFeeSource;
139
+ /**
140
+ * @internal Test-only: layer fake `PriceUpdateRule`s on top of the
141
+ * production registry (see `rule-registry.ts`'s `resolveOracleRule`).
142
+ * Production callers never set this — routing is by `host.oracleSource`
143
+ * alone.
144
+ */
145
+ ruleOverrides?: Partial<Record<OracleSource, PriceUpdateRule>>;
146
+ /**
147
+ * BE prefetch-cache seam: checked per group BEFORE that group's live
148
+ * `rule.fetchUpdateData`. See {@link UpdateDataProvider}. A cache miss
149
+ * (`null`) or a throw from the provider falls back to the live fetch —
150
+ * a degraded/broken cache must never break the money path; a
151
+ * kind-mismatched hit (the provider handed back the wrong rule's
152
+ * payload) throws instead, since that is a caller bug, not a cache miss.
153
+ */
154
+ updateDataProvider?: UpdateDataProvider;
74
155
  }): Promise<void>;