@oddmaki-protocol/sdk 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -8613,6 +8613,14 @@ declare class TradeModule extends BaseModule {
8613
8613
  * Cancel an order
8614
8614
  */
8615
8615
  cancelOrder(orderId: bigint): Promise<`0x${string}`>;
8616
+ /**
8617
+ * Cancel all remaining orders on a resolved market in a single transaction.
8618
+ * Regular cancelOrder / batchCancelOrders revert once the market is no longer
8619
+ * active, so this is the only way to clear stale orders post-resolution.
8620
+ * @param marketId - The resolved market
8621
+ * @param orderIds - Order IDs to cancel (must belong to caller)
8622
+ */
8623
+ cancelOrdersOnResolvedMarket(marketId: bigint, orderIds: bigint[]): Promise<`0x${string}`>;
8616
8624
  /**
8617
8625
  * Execute a market order (FOK or FAK)
8618
8626
  *
@@ -9412,6 +9420,20 @@ interface PriceMarketData {
9412
9420
  resolutionWindow: bigint;
9413
9421
  resolved: boolean;
9414
9422
  strikePrice: bigint;
9423
+ /**
9424
+ * Pyth VAA publishTime for the opening-price capture (seconds since epoch).
9425
+ * 0 for strike markets (no opening price is captured).
9426
+ */
9427
+ openPriceTime: bigint;
9428
+ }
9429
+ /**
9430
+ * Latest Pyth price update data plus the signed VAA's publishTime.
9431
+ * `fetchedAt` is the SDK-local unix timestamp (seconds) at fetch time.
9432
+ */
9433
+ interface PythUpdate {
9434
+ updateData: `0x${string}`[];
9435
+ publishTime: bigint;
9436
+ fetchedAt: bigint;
9415
9437
  }
9416
9438
  declare class PriceMarketModule extends BaseModule {
9417
9439
  /**
@@ -9471,6 +9493,23 @@ declare class PriceMarketModule extends BaseModule {
9471
9493
  * Get the Pyth contract address configured on the Diamond
9472
9494
  */
9473
9495
  getPythContract(): Promise<Address>;
9496
+ /**
9497
+ * Set the Pyth oracle contract address. Diamond owner only.
9498
+ */
9499
+ setPythContract(pythContract: Address): Promise<`0x${string}`>;
9500
+ /**
9501
+ * Get the effective opening-price staleness window in seconds.
9502
+ *
9503
+ * A submitted VAA's `publishTime` must fall within
9504
+ * `[block.timestamp - openMaxStaleness, block.timestamp + OPEN_FUTURE_SKEW]`
9505
+ * at `createPriceMarketPyth` time. Defaults to 300s when unset on-chain.
9506
+ */
9507
+ getOpenMaxStaleness(): Promise<bigint>;
9508
+ /**
9509
+ * Set the opening-price staleness window (seconds). Diamond owner only.
9510
+ * Pass 0 to fall back to the built-in default.
9511
+ */
9512
+ setOpenMaxStaleness(openMaxStaleness: bigint): Promise<`0x${string}`>;
9474
9513
  /**
9475
9514
  * Shared pre-flight checks: creation fee allowance, ancillary data, tags
9476
9515
  */
@@ -9481,7 +9520,31 @@ declare class PriceMarketModule extends BaseModule {
9481
9520
  private _preparePythUpdate;
9482
9521
  private formatAncillaryData;
9483
9522
  /**
9484
- * Fetch latest Pyth price update data from Hermes API
9523
+ * Fetch latest Pyth price update from Hermes — bytes plus the VAA's publishTime.
9524
+ *
9525
+ * Use this (or {@link fetchFreshPythUpdate}) instead of re-rolling Hermes
9526
+ * calls when building `createPriceMarketPyth` transactions. The on-chain
9527
+ * staleness window defaults to 300s — if the user takes longer than that
9528
+ * to sign, the VAA will be rejected.
9529
+ */
9530
+ fetchPythLatestUpdate(feedId: `0x${string}`): Promise<PythUpdate>;
9531
+ /**
9532
+ * Return a Pyth update that is fresh enough to pass the on-chain staleness check.
9533
+ *
9534
+ * If `cached` is provided and still within `maxAgeSeconds`, it is returned as-is.
9535
+ * Otherwise Hermes is re-queried; if the newly fetched VAA is also older than
9536
+ * `maxAgeSeconds` (e.g. feed is quiet), it retries up to `maxAttempts`.
9537
+ *
9538
+ * Defaults: `maxAgeSeconds = 120` (leaves ~180s headroom under the 300s default
9539
+ * on-chain window), `maxAttempts = 3`.
9540
+ */
9541
+ fetchFreshPythUpdate(feedId: `0x${string}`, options?: {
9542
+ maxAgeSeconds?: number;
9543
+ maxAttempts?: number;
9544
+ cached?: PythUpdate;
9545
+ }): Promise<PythUpdate>;
9546
+ /**
9547
+ * Fetch latest Pyth price update data from Hermes API (raw bytes only).
9485
9548
  */
9486
9549
  private fetchPythUpdateData;
9487
9550
  /**
@@ -15026,6 +15089,11 @@ var PriceMarketFacet = [
15026
15089
  name: "strikePrice",
15027
15090
  type: "int64",
15028
15091
  internalType: "int64"
15092
+ },
15093
+ {
15094
+ name: "openPriceTime",
15095
+ type: "uint256",
15096
+ internalType: "uint256"
15029
15097
  }
15030
15098
  ],
15031
15099
  stateMutability: "view"
@@ -15173,6 +15241,34 @@ var PythResolutionFacet = [
15173
15241
  ],
15174
15242
  stateMutability: "nonpayable"
15175
15243
  },
15244
+ {
15245
+ type: "function",
15246
+ name: "setOpenMaxStaleness",
15247
+ inputs: [
15248
+ {
15249
+ name: "openMaxStaleness",
15250
+ type: "uint256",
15251
+ internalType: "uint256"
15252
+ }
15253
+ ],
15254
+ outputs: [
15255
+ ],
15256
+ stateMutability: "nonpayable"
15257
+ },
15258
+ {
15259
+ type: "function",
15260
+ name: "getOpenMaxStaleness",
15261
+ inputs: [
15262
+ ],
15263
+ outputs: [
15264
+ {
15265
+ name: "",
15266
+ type: "uint256",
15267
+ internalType: "uint256"
15268
+ }
15269
+ ],
15270
+ stateMutability: "view"
15271
+ },
15176
15272
  {
15177
15273
  type: "event",
15178
15274
  name: "MarketCreated",
@@ -15395,6 +15491,19 @@ var PythResolutionFacet = [
15395
15491
  ],
15396
15492
  anonymous: false
15397
15493
  },
15494
+ {
15495
+ type: "event",
15496
+ name: "OpenMaxStalenessUpdated",
15497
+ inputs: [
15498
+ {
15499
+ name: "openMaxStaleness",
15500
+ type: "uint256",
15501
+ indexed: false,
15502
+ internalType: "uint256"
15503
+ }
15504
+ ],
15505
+ anonymous: false
15506
+ },
15398
15507
  {
15399
15508
  type: "event",
15400
15509
  name: "WrappedCollateralRegistered",
@@ -16866,4 +16975,4 @@ declare function parseMetadata<T extends {
16866
16975
 
16867
16976
  declare const version = "0.1.0";
16868
16977
 
16869
- export { AccessControlFacet as AccessControlFacetABI, AccessControlModule, BatchOrdersFacet as BatchOrdersFacetABI, CONTRACT_ADDRESSES, type ChancePercentInput, ConditionalTokens as ConditionalTokensABI, DEFAULT_CHAIN, ERC20 as ERC20ABI, FeedProvider, GET_ALL_MARKETS_FEED, GET_ALL_MARKETS_FEED_BY_VOLUME, GET_CHART_TRADES, GET_CHART_TRADES_ALL, GET_GROUP_MARKETS, GET_LEADERBOARD, GET_MARKET, GET_MARKETS, GET_MARKETS_WITH_PRICING, GET_MARKET_GROUP, GET_MARKET_GROUPS, GET_MARKET_GROUP_ITEM, GET_MARKET_TOP_HOLDERS, GET_ORDERS, GET_PROTOCOL_STATS, GET_QUESTION, GET_QUESTIONS, GET_RECENT_MARKETS, GET_RECENT_TRADES, GET_TOP_OF_BOOK, GET_TRADER_CLOSED_POSITIONS, GET_TRADER_FILLS, GET_TRADER_POSITIONS, GET_TRADER_PROFILE, GET_TRADES, GET_UNIFIED_MARKET_FEED, GET_UNIFIED_MARKET_FEED_BY_VOLUME, GET_USER, GET_VENUES, LimitOrdersFacet as LimitOrdersFacetABI, MarketGroupFacet as MarketGroupFacetABI, type MarketMetadata, MarketModule, MarketOrdersFacet as MarketOrdersFacetABI, type MarketQuestion, MarketsFacet as MarketsFacetABI, MatchingFacet as MatchingFacetABI, MetadataFacet as MetadataFacetABI, NegRiskFacet as NegRiskFacetABI, OddMakiClient, type OddMakiClientConfig, type OddMakiConfig, OrderBookFacet as OrderBookFacetABI, PROTOCOL_FEES, type PriceMarketData, PriceMarketFacet as PriceMarketFacetABI, PriceMarketModule, ProtocolFacet as ProtocolFacetABI, PublicModule, PythResolutionFacet as PythResolutionFacetABI, ResolutionFacet as ResolutionFacetABI, SubgraphClient, type SubgraphMarketPriceData, TICK_SIZE_FINE, TICK_SIZE_STANDARD, TagsFacet as TagsFacetABI, TokenModule, type TopOfBookEntry, TradeModule, UMA_DEFAULTS, UmaModule, VALID_TICK_SIZES, VaultFacet as VaultFacetABI, VenueFacet as VenueFacetABI, type VenueMetadata, VenueModule, WhitelistAccessControl as WhitelistAccessControlABI, calculateChancePercent, clearDecimalsCache, createExpiry, createOddMakiClient, formatAmount, formatAncillaryData, formatTimestamp, getCachedTokenDecimals, getOutcomePrice, getTokenDecimals, isValidTickSize, parseAmount, parseAncillaryData, parseMetadata, parseTokenAmount, priceToTick, resolveIPFSUri, tickToPercentage, tickToPrice, version };
16978
+ export { AccessControlFacet as AccessControlFacetABI, AccessControlModule, BatchOrdersFacet as BatchOrdersFacetABI, CONTRACT_ADDRESSES, type ChancePercentInput, ConditionalTokens as ConditionalTokensABI, DEFAULT_CHAIN, ERC20 as ERC20ABI, FeedProvider, GET_ALL_MARKETS_FEED, GET_ALL_MARKETS_FEED_BY_VOLUME, GET_CHART_TRADES, GET_CHART_TRADES_ALL, GET_GROUP_MARKETS, GET_LEADERBOARD, GET_MARKET, GET_MARKETS, GET_MARKETS_WITH_PRICING, GET_MARKET_GROUP, GET_MARKET_GROUPS, GET_MARKET_GROUP_ITEM, GET_MARKET_TOP_HOLDERS, GET_ORDERS, GET_PROTOCOL_STATS, GET_QUESTION, GET_QUESTIONS, GET_RECENT_MARKETS, GET_RECENT_TRADES, GET_TOP_OF_BOOK, GET_TRADER_CLOSED_POSITIONS, GET_TRADER_FILLS, GET_TRADER_POSITIONS, GET_TRADER_PROFILE, GET_TRADES, GET_UNIFIED_MARKET_FEED, GET_UNIFIED_MARKET_FEED_BY_VOLUME, GET_USER, GET_VENUES, LimitOrdersFacet as LimitOrdersFacetABI, MarketGroupFacet as MarketGroupFacetABI, type MarketMetadata, MarketModule, MarketOrdersFacet as MarketOrdersFacetABI, type MarketQuestion, MarketsFacet as MarketsFacetABI, MatchingFacet as MatchingFacetABI, MetadataFacet as MetadataFacetABI, NegRiskFacet as NegRiskFacetABI, OddMakiClient, type OddMakiClientConfig, type OddMakiConfig, OrderBookFacet as OrderBookFacetABI, PROTOCOL_FEES, type PriceMarketData, PriceMarketFacet as PriceMarketFacetABI, PriceMarketModule, ProtocolFacet as ProtocolFacetABI, PublicModule, PythResolutionFacet as PythResolutionFacetABI, type PythUpdate, ResolutionFacet as ResolutionFacetABI, SubgraphClient, type SubgraphMarketPriceData, TICK_SIZE_FINE, TICK_SIZE_STANDARD, TagsFacet as TagsFacetABI, TokenModule, type TopOfBookEntry, TradeModule, UMA_DEFAULTS, UmaModule, VALID_TICK_SIZES, VaultFacet as VaultFacetABI, VenueFacet as VenueFacetABI, type VenueMetadata, VenueModule, WhitelistAccessControl as WhitelistAccessControlABI, calculateChancePercent, clearDecimalsCache, createExpiry, createOddMakiClient, formatAmount, formatAncillaryData, formatTimestamp, getCachedTokenDecimals, getOutcomePrice, getTokenDecimals, isValidTickSize, parseAmount, parseAncillaryData, parseMetadata, parseTokenAmount, priceToTick, resolveIPFSUri, tickToPercentage, tickToPrice, version };
package/dist/index.d.ts CHANGED
@@ -8613,6 +8613,14 @@ declare class TradeModule extends BaseModule {
8613
8613
  * Cancel an order
8614
8614
  */
8615
8615
  cancelOrder(orderId: bigint): Promise<`0x${string}`>;
8616
+ /**
8617
+ * Cancel all remaining orders on a resolved market in a single transaction.
8618
+ * Regular cancelOrder / batchCancelOrders revert once the market is no longer
8619
+ * active, so this is the only way to clear stale orders post-resolution.
8620
+ * @param marketId - The resolved market
8621
+ * @param orderIds - Order IDs to cancel (must belong to caller)
8622
+ */
8623
+ cancelOrdersOnResolvedMarket(marketId: bigint, orderIds: bigint[]): Promise<`0x${string}`>;
8616
8624
  /**
8617
8625
  * Execute a market order (FOK or FAK)
8618
8626
  *
@@ -9412,6 +9420,20 @@ interface PriceMarketData {
9412
9420
  resolutionWindow: bigint;
9413
9421
  resolved: boolean;
9414
9422
  strikePrice: bigint;
9423
+ /**
9424
+ * Pyth VAA publishTime for the opening-price capture (seconds since epoch).
9425
+ * 0 for strike markets (no opening price is captured).
9426
+ */
9427
+ openPriceTime: bigint;
9428
+ }
9429
+ /**
9430
+ * Latest Pyth price update data plus the signed VAA's publishTime.
9431
+ * `fetchedAt` is the SDK-local unix timestamp (seconds) at fetch time.
9432
+ */
9433
+ interface PythUpdate {
9434
+ updateData: `0x${string}`[];
9435
+ publishTime: bigint;
9436
+ fetchedAt: bigint;
9415
9437
  }
9416
9438
  declare class PriceMarketModule extends BaseModule {
9417
9439
  /**
@@ -9471,6 +9493,23 @@ declare class PriceMarketModule extends BaseModule {
9471
9493
  * Get the Pyth contract address configured on the Diamond
9472
9494
  */
9473
9495
  getPythContract(): Promise<Address>;
9496
+ /**
9497
+ * Set the Pyth oracle contract address. Diamond owner only.
9498
+ */
9499
+ setPythContract(pythContract: Address): Promise<`0x${string}`>;
9500
+ /**
9501
+ * Get the effective opening-price staleness window in seconds.
9502
+ *
9503
+ * A submitted VAA's `publishTime` must fall within
9504
+ * `[block.timestamp - openMaxStaleness, block.timestamp + OPEN_FUTURE_SKEW]`
9505
+ * at `createPriceMarketPyth` time. Defaults to 300s when unset on-chain.
9506
+ */
9507
+ getOpenMaxStaleness(): Promise<bigint>;
9508
+ /**
9509
+ * Set the opening-price staleness window (seconds). Diamond owner only.
9510
+ * Pass 0 to fall back to the built-in default.
9511
+ */
9512
+ setOpenMaxStaleness(openMaxStaleness: bigint): Promise<`0x${string}`>;
9474
9513
  /**
9475
9514
  * Shared pre-flight checks: creation fee allowance, ancillary data, tags
9476
9515
  */
@@ -9481,7 +9520,31 @@ declare class PriceMarketModule extends BaseModule {
9481
9520
  private _preparePythUpdate;
9482
9521
  private formatAncillaryData;
9483
9522
  /**
9484
- * Fetch latest Pyth price update data from Hermes API
9523
+ * Fetch latest Pyth price update from Hermes — bytes plus the VAA's publishTime.
9524
+ *
9525
+ * Use this (or {@link fetchFreshPythUpdate}) instead of re-rolling Hermes
9526
+ * calls when building `createPriceMarketPyth` transactions. The on-chain
9527
+ * staleness window defaults to 300s — if the user takes longer than that
9528
+ * to sign, the VAA will be rejected.
9529
+ */
9530
+ fetchPythLatestUpdate(feedId: `0x${string}`): Promise<PythUpdate>;
9531
+ /**
9532
+ * Return a Pyth update that is fresh enough to pass the on-chain staleness check.
9533
+ *
9534
+ * If `cached` is provided and still within `maxAgeSeconds`, it is returned as-is.
9535
+ * Otherwise Hermes is re-queried; if the newly fetched VAA is also older than
9536
+ * `maxAgeSeconds` (e.g. feed is quiet), it retries up to `maxAttempts`.
9537
+ *
9538
+ * Defaults: `maxAgeSeconds = 120` (leaves ~180s headroom under the 300s default
9539
+ * on-chain window), `maxAttempts = 3`.
9540
+ */
9541
+ fetchFreshPythUpdate(feedId: `0x${string}`, options?: {
9542
+ maxAgeSeconds?: number;
9543
+ maxAttempts?: number;
9544
+ cached?: PythUpdate;
9545
+ }): Promise<PythUpdate>;
9546
+ /**
9547
+ * Fetch latest Pyth price update data from Hermes API (raw bytes only).
9485
9548
  */
9486
9549
  private fetchPythUpdateData;
9487
9550
  /**
@@ -15026,6 +15089,11 @@ var PriceMarketFacet = [
15026
15089
  name: "strikePrice",
15027
15090
  type: "int64",
15028
15091
  internalType: "int64"
15092
+ },
15093
+ {
15094
+ name: "openPriceTime",
15095
+ type: "uint256",
15096
+ internalType: "uint256"
15029
15097
  }
15030
15098
  ],
15031
15099
  stateMutability: "view"
@@ -15173,6 +15241,34 @@ var PythResolutionFacet = [
15173
15241
  ],
15174
15242
  stateMutability: "nonpayable"
15175
15243
  },
15244
+ {
15245
+ type: "function",
15246
+ name: "setOpenMaxStaleness",
15247
+ inputs: [
15248
+ {
15249
+ name: "openMaxStaleness",
15250
+ type: "uint256",
15251
+ internalType: "uint256"
15252
+ }
15253
+ ],
15254
+ outputs: [
15255
+ ],
15256
+ stateMutability: "nonpayable"
15257
+ },
15258
+ {
15259
+ type: "function",
15260
+ name: "getOpenMaxStaleness",
15261
+ inputs: [
15262
+ ],
15263
+ outputs: [
15264
+ {
15265
+ name: "",
15266
+ type: "uint256",
15267
+ internalType: "uint256"
15268
+ }
15269
+ ],
15270
+ stateMutability: "view"
15271
+ },
15176
15272
  {
15177
15273
  type: "event",
15178
15274
  name: "MarketCreated",
@@ -15395,6 +15491,19 @@ var PythResolutionFacet = [
15395
15491
  ],
15396
15492
  anonymous: false
15397
15493
  },
15494
+ {
15495
+ type: "event",
15496
+ name: "OpenMaxStalenessUpdated",
15497
+ inputs: [
15498
+ {
15499
+ name: "openMaxStaleness",
15500
+ type: "uint256",
15501
+ indexed: false,
15502
+ internalType: "uint256"
15503
+ }
15504
+ ],
15505
+ anonymous: false
15506
+ },
15398
15507
  {
15399
15508
  type: "event",
15400
15509
  name: "WrappedCollateralRegistered",
@@ -16866,4 +16975,4 @@ declare function parseMetadata<T extends {
16866
16975
 
16867
16976
  declare const version = "0.1.0";
16868
16977
 
16869
- export { AccessControlFacet as AccessControlFacetABI, AccessControlModule, BatchOrdersFacet as BatchOrdersFacetABI, CONTRACT_ADDRESSES, type ChancePercentInput, ConditionalTokens as ConditionalTokensABI, DEFAULT_CHAIN, ERC20 as ERC20ABI, FeedProvider, GET_ALL_MARKETS_FEED, GET_ALL_MARKETS_FEED_BY_VOLUME, GET_CHART_TRADES, GET_CHART_TRADES_ALL, GET_GROUP_MARKETS, GET_LEADERBOARD, GET_MARKET, GET_MARKETS, GET_MARKETS_WITH_PRICING, GET_MARKET_GROUP, GET_MARKET_GROUPS, GET_MARKET_GROUP_ITEM, GET_MARKET_TOP_HOLDERS, GET_ORDERS, GET_PROTOCOL_STATS, GET_QUESTION, GET_QUESTIONS, GET_RECENT_MARKETS, GET_RECENT_TRADES, GET_TOP_OF_BOOK, GET_TRADER_CLOSED_POSITIONS, GET_TRADER_FILLS, GET_TRADER_POSITIONS, GET_TRADER_PROFILE, GET_TRADES, GET_UNIFIED_MARKET_FEED, GET_UNIFIED_MARKET_FEED_BY_VOLUME, GET_USER, GET_VENUES, LimitOrdersFacet as LimitOrdersFacetABI, MarketGroupFacet as MarketGroupFacetABI, type MarketMetadata, MarketModule, MarketOrdersFacet as MarketOrdersFacetABI, type MarketQuestion, MarketsFacet as MarketsFacetABI, MatchingFacet as MatchingFacetABI, MetadataFacet as MetadataFacetABI, NegRiskFacet as NegRiskFacetABI, OddMakiClient, type OddMakiClientConfig, type OddMakiConfig, OrderBookFacet as OrderBookFacetABI, PROTOCOL_FEES, type PriceMarketData, PriceMarketFacet as PriceMarketFacetABI, PriceMarketModule, ProtocolFacet as ProtocolFacetABI, PublicModule, PythResolutionFacet as PythResolutionFacetABI, ResolutionFacet as ResolutionFacetABI, SubgraphClient, type SubgraphMarketPriceData, TICK_SIZE_FINE, TICK_SIZE_STANDARD, TagsFacet as TagsFacetABI, TokenModule, type TopOfBookEntry, TradeModule, UMA_DEFAULTS, UmaModule, VALID_TICK_SIZES, VaultFacet as VaultFacetABI, VenueFacet as VenueFacetABI, type VenueMetadata, VenueModule, WhitelistAccessControl as WhitelistAccessControlABI, calculateChancePercent, clearDecimalsCache, createExpiry, createOddMakiClient, formatAmount, formatAncillaryData, formatTimestamp, getCachedTokenDecimals, getOutcomePrice, getTokenDecimals, isValidTickSize, parseAmount, parseAncillaryData, parseMetadata, parseTokenAmount, priceToTick, resolveIPFSUri, tickToPercentage, tickToPrice, version };
16978
+ export { AccessControlFacet as AccessControlFacetABI, AccessControlModule, BatchOrdersFacet as BatchOrdersFacetABI, CONTRACT_ADDRESSES, type ChancePercentInput, ConditionalTokens as ConditionalTokensABI, DEFAULT_CHAIN, ERC20 as ERC20ABI, FeedProvider, GET_ALL_MARKETS_FEED, GET_ALL_MARKETS_FEED_BY_VOLUME, GET_CHART_TRADES, GET_CHART_TRADES_ALL, GET_GROUP_MARKETS, GET_LEADERBOARD, GET_MARKET, GET_MARKETS, GET_MARKETS_WITH_PRICING, GET_MARKET_GROUP, GET_MARKET_GROUPS, GET_MARKET_GROUP_ITEM, GET_MARKET_TOP_HOLDERS, GET_ORDERS, GET_PROTOCOL_STATS, GET_QUESTION, GET_QUESTIONS, GET_RECENT_MARKETS, GET_RECENT_TRADES, GET_TOP_OF_BOOK, GET_TRADER_CLOSED_POSITIONS, GET_TRADER_FILLS, GET_TRADER_POSITIONS, GET_TRADER_PROFILE, GET_TRADES, GET_UNIFIED_MARKET_FEED, GET_UNIFIED_MARKET_FEED_BY_VOLUME, GET_USER, GET_VENUES, LimitOrdersFacet as LimitOrdersFacetABI, MarketGroupFacet as MarketGroupFacetABI, type MarketMetadata, MarketModule, MarketOrdersFacet as MarketOrdersFacetABI, type MarketQuestion, MarketsFacet as MarketsFacetABI, MatchingFacet as MatchingFacetABI, MetadataFacet as MetadataFacetABI, NegRiskFacet as NegRiskFacetABI, OddMakiClient, type OddMakiClientConfig, type OddMakiConfig, OrderBookFacet as OrderBookFacetABI, PROTOCOL_FEES, type PriceMarketData, PriceMarketFacet as PriceMarketFacetABI, PriceMarketModule, ProtocolFacet as ProtocolFacetABI, PublicModule, PythResolutionFacet as PythResolutionFacetABI, type PythUpdate, ResolutionFacet as ResolutionFacetABI, SubgraphClient, type SubgraphMarketPriceData, TICK_SIZE_FINE, TICK_SIZE_STANDARD, TagsFacet as TagsFacetABI, TokenModule, type TopOfBookEntry, TradeModule, UMA_DEFAULTS, UmaModule, VALID_TICK_SIZES, VaultFacet as VaultFacetABI, VenueFacet as VenueFacetABI, type VenueMetadata, VenueModule, WhitelistAccessControl as WhitelistAccessControlABI, calculateChancePercent, clearDecimalsCache, createExpiry, createOddMakiClient, formatAmount, formatAncillaryData, formatTimestamp, getCachedTokenDecimals, getOutcomePrice, getTokenDecimals, isValidTickSize, parseAmount, parseAncillaryData, parseMetadata, parseTokenAmount, priceToTick, resolveIPFSUri, tickToPercentage, tickToPrice, version };
package/dist/index.js CHANGED
@@ -7,9 +7,9 @@ var graphqlRequest = require('graphql-request');
7
7
  // src/client.ts
8
8
  var CONTRACT_ADDRESSES = {
9
9
  [chains.baseSepolia.id]: {
10
- diamond: "0x2612a6949a4eeafa0bc39a7d82e0c926d4180d99",
10
+ diamond: "0x188563069e0ae7247f0e2f0fce0382f0ed28d31a",
11
11
  conditionalTokens: "0x7364747372Ac4a175B5326f5B2C9CB1C271d32e8",
12
- usdc: "0x643a4ec97528c719bbaa5457806d6898321df7d4",
12
+ usdc: "0xb7e73d2848dd908a90a50ba679719eb9375c3fdf",
13
13
  subgraph: "https://api.studio.thegraph.com/query/1716020/oddmaki/version/latest"
14
14
  }
15
15
  };
@@ -5047,6 +5047,11 @@ var PriceMarketFacet_default = [
5047
5047
  name: "strikePrice",
5048
5048
  type: "int64",
5049
5049
  internalType: "int64"
5050
+ },
5051
+ {
5052
+ name: "openPriceTime",
5053
+ type: "uint256",
5054
+ internalType: "uint256"
5050
5055
  }
5051
5056
  ],
5052
5057
  stateMutability: "view"
@@ -5192,6 +5197,32 @@ var PythResolutionFacet_default = [
5192
5197
  outputs: [],
5193
5198
  stateMutability: "nonpayable"
5194
5199
  },
5200
+ {
5201
+ type: "function",
5202
+ name: "setOpenMaxStaleness",
5203
+ inputs: [
5204
+ {
5205
+ name: "openMaxStaleness",
5206
+ type: "uint256",
5207
+ internalType: "uint256"
5208
+ }
5209
+ ],
5210
+ outputs: [],
5211
+ stateMutability: "nonpayable"
5212
+ },
5213
+ {
5214
+ type: "function",
5215
+ name: "getOpenMaxStaleness",
5216
+ inputs: [],
5217
+ outputs: [
5218
+ {
5219
+ name: "",
5220
+ type: "uint256",
5221
+ internalType: "uint256"
5222
+ }
5223
+ ],
5224
+ stateMutability: "view"
5225
+ },
5195
5226
  {
5196
5227
  type: "event",
5197
5228
  name: "MarketCreated",
@@ -5414,6 +5445,19 @@ var PythResolutionFacet_default = [
5414
5445
  ],
5415
5446
  anonymous: false
5416
5447
  },
5448
+ {
5449
+ type: "event",
5450
+ name: "OpenMaxStalenessUpdated",
5451
+ inputs: [
5452
+ {
5453
+ name: "openMaxStaleness",
5454
+ type: "uint256",
5455
+ indexed: false,
5456
+ internalType: "uint256"
5457
+ }
5458
+ ],
5459
+ anonymous: false
5460
+ },
5417
5461
  {
5418
5462
  type: "event",
5419
5463
  name: "WrappedCollateralRegistered",
@@ -7844,6 +7888,25 @@ var TradeModule = class extends BaseModule {
7844
7888
  });
7845
7889
  return wallet.writeContract(request);
7846
7890
  }
7891
+ /**
7892
+ * Cancel all remaining orders on a resolved market in a single transaction.
7893
+ * Regular cancelOrder / batchCancelOrders revert once the market is no longer
7894
+ * active, so this is the only way to clear stale orders post-resolution.
7895
+ * @param marketId - The resolved market
7896
+ * @param orderIds - Order IDs to cancel (must belong to caller)
7897
+ */
7898
+ async cancelOrdersOnResolvedMarket(marketId, orderIds) {
7899
+ const wallet = this.walletClient;
7900
+ const [account] = await wallet.getAddresses();
7901
+ const { request } = await this.publicClient.simulateContract({
7902
+ address: this.config.diamondAddress,
7903
+ abi: LimitOrdersFacet_default,
7904
+ functionName: "cancelOrdersOnResolvedMarket",
7905
+ args: [marketId, orderIds],
7906
+ account
7907
+ });
7908
+ return wallet.writeContract(request);
7909
+ }
7847
7910
  /**
7848
7911
  * Execute a market order (FOK or FAK)
7849
7912
  *
@@ -10465,6 +10528,8 @@ var FeedProvider = /* @__PURE__ */ ((FeedProvider2) => {
10465
10528
  FeedProvider2[FeedProvider2["CHAINLINK"] = 1] = "CHAINLINK";
10466
10529
  return FeedProvider2;
10467
10530
  })(FeedProvider || {});
10531
+ var DEFAULT_FRESH_MAX_AGE_SECONDS = 120;
10532
+ var DEFAULT_FRESH_MAX_ATTEMPTS = 3;
10468
10533
  var PriceMarketModule = class extends BaseModule {
10469
10534
  /**
10470
10535
  * Create a Pyth-powered price market
@@ -10608,7 +10673,8 @@ var PriceMarketModule = class extends BaseModule {
10608
10673
  finalPrice: BigInt(result[5]),
10609
10674
  resolutionWindow: BigInt(result[6]),
10610
10675
  resolved: result[7],
10611
- strikePrice: BigInt(result[8])
10676
+ strikePrice: BigInt(result[8]),
10677
+ openPriceTime: BigInt(result[9])
10612
10678
  };
10613
10679
  }
10614
10680
  /**
@@ -10621,6 +10687,51 @@ var PriceMarketModule = class extends BaseModule {
10621
10687
  functionName: "getPythContract"
10622
10688
  });
10623
10689
  }
10690
+ /**
10691
+ * Set the Pyth oracle contract address. Diamond owner only.
10692
+ */
10693
+ async setPythContract(pythContract) {
10694
+ const wallet = this.walletClient;
10695
+ const [account] = await wallet.getAddresses();
10696
+ const { request } = await this.publicClient.simulateContract({
10697
+ address: this.config.diamondAddress,
10698
+ abi: PythResolutionFacet_default,
10699
+ functionName: "setPythContract",
10700
+ args: [pythContract],
10701
+ account
10702
+ });
10703
+ return wallet.writeContract(request);
10704
+ }
10705
+ /**
10706
+ * Get the effective opening-price staleness window in seconds.
10707
+ *
10708
+ * A submitted VAA's `publishTime` must fall within
10709
+ * `[block.timestamp - openMaxStaleness, block.timestamp + OPEN_FUTURE_SKEW]`
10710
+ * at `createPriceMarketPyth` time. Defaults to 300s when unset on-chain.
10711
+ */
10712
+ async getOpenMaxStaleness() {
10713
+ return await this.publicClient.readContract({
10714
+ address: this.config.diamondAddress,
10715
+ abi: PythResolutionFacet_default,
10716
+ functionName: "getOpenMaxStaleness"
10717
+ });
10718
+ }
10719
+ /**
10720
+ * Set the opening-price staleness window (seconds). Diamond owner only.
10721
+ * Pass 0 to fall back to the built-in default.
10722
+ */
10723
+ async setOpenMaxStaleness(openMaxStaleness) {
10724
+ const wallet = this.walletClient;
10725
+ const [account] = await wallet.getAddresses();
10726
+ const { request } = await this.publicClient.simulateContract({
10727
+ address: this.config.diamondAddress,
10728
+ abi: PythResolutionFacet_default,
10729
+ functionName: "setOpenMaxStaleness",
10730
+ args: [openMaxStaleness],
10731
+ account
10732
+ });
10733
+ return wallet.writeContract(request);
10734
+ }
10624
10735
  // ---- Private helpers ----
10625
10736
  /**
10626
10737
  * Shared pre-flight checks: creation fee allowance, ancillary data, tags
@@ -10673,20 +10784,73 @@ var PriceMarketModule = class extends BaseModule {
10673
10784
  return viem.stringToHex(data);
10674
10785
  }
10675
10786
  /**
10676
- * Fetch latest Pyth price update data from Hermes API
10787
+ * Fetch latest Pyth price update from Hermes — bytes plus the VAA's publishTime.
10788
+ *
10789
+ * Use this (or {@link fetchFreshPythUpdate}) instead of re-rolling Hermes
10790
+ * calls when building `createPriceMarketPyth` transactions. The on-chain
10791
+ * staleness window defaults to 300s — if the user takes longer than that
10792
+ * to sign, the VAA will be rejected.
10677
10793
  */
10678
- async fetchPythUpdateData(feedId) {
10794
+ async fetchPythLatestUpdate(feedId) {
10679
10795
  const url = `${PYTH_HERMES_BASE}/v2/updates/price/latest?ids[]=${feedId}`;
10680
10796
  const response = await fetch(url);
10681
10797
  if (!response.ok) {
10682
- throw new Error(`Pyth Hermes API error: ${response.status} ${response.statusText}`);
10798
+ throw new Error(
10799
+ `Pyth Hermes API error: ${response.status} ${response.statusText}`
10800
+ );
10683
10801
  }
10684
10802
  const data = await response.json();
10685
10803
  const updateData = data.binary?.data;
10686
10804
  if (!updateData || updateData.length === 0) {
10687
10805
  throw new Error("No price update data returned from Pyth Hermes");
10688
10806
  }
10689
- return updateData.map((d) => `0x${d}`);
10807
+ const parsed = data.parsed?.[0];
10808
+ const publishTimeRaw = parsed?.price?.publish_time;
10809
+ if (typeof publishTimeRaw !== "number") {
10810
+ throw new Error("Pyth Hermes response missing parsed.price.publish_time");
10811
+ }
10812
+ return {
10813
+ updateData: updateData.map((d) => `0x${d}`),
10814
+ publishTime: BigInt(publishTimeRaw),
10815
+ fetchedAt: BigInt(Math.floor(Date.now() / 1e3))
10816
+ };
10817
+ }
10818
+ /**
10819
+ * Return a Pyth update that is fresh enough to pass the on-chain staleness check.
10820
+ *
10821
+ * If `cached` is provided and still within `maxAgeSeconds`, it is returned as-is.
10822
+ * Otherwise Hermes is re-queried; if the newly fetched VAA is also older than
10823
+ * `maxAgeSeconds` (e.g. feed is quiet), it retries up to `maxAttempts`.
10824
+ *
10825
+ * Defaults: `maxAgeSeconds = 120` (leaves ~180s headroom under the 300s default
10826
+ * on-chain window), `maxAttempts = 3`.
10827
+ */
10828
+ async fetchFreshPythUpdate(feedId, options = {}) {
10829
+ const maxAgeSeconds = options.maxAgeSeconds ?? DEFAULT_FRESH_MAX_AGE_SECONDS;
10830
+ const maxAttempts = options.maxAttempts ?? DEFAULT_FRESH_MAX_ATTEMPTS;
10831
+ const isFresh = (u) => {
10832
+ const now = BigInt(Math.floor(Date.now() / 1e3));
10833
+ return now - u.publishTime <= BigInt(maxAgeSeconds);
10834
+ };
10835
+ if (options.cached && isFresh(options.cached)) {
10836
+ return options.cached;
10837
+ }
10838
+ let latest;
10839
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
10840
+ latest = await this.fetchPythLatestUpdate(feedId);
10841
+ if (isFresh(latest)) return latest;
10842
+ }
10843
+ if (!latest) {
10844
+ throw new Error("Failed to fetch any Pyth update from Hermes");
10845
+ }
10846
+ return latest;
10847
+ }
10848
+ /**
10849
+ * Fetch latest Pyth price update data from Hermes API (raw bytes only).
10850
+ */
10851
+ async fetchPythUpdateData(feedId) {
10852
+ const { updateData } = await this.fetchPythLatestUpdate(feedId);
10853
+ return updateData;
10690
10854
  }
10691
10855
  /**
10692
10856
  * Fetch historical Pyth price update data at a specific timestamp