@oddmaki-protocol/sdk 1.12.1 → 1.13.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
@@ -17651,6 +17651,116 @@ declare function parseMetadata<T extends {
17651
17651
  version: number;
17652
17652
  }>(json: string): T | null;
17653
17653
 
17654
+ /**
17655
+ * Fee-aware pricing helpers.
17656
+ *
17657
+ * The matching engine's mint-to-fill / merge-to-fill paths require bids/asks to
17658
+ * cover 1.0 PLUS total fees (protocol + venue + operator). Normal fills also
17659
+ * require taker buyers to bid at ask × (1 + totalFeeBps/10_000) for the full
17660
+ * quantity to fill (otherwise qty is reduced to whatever the taker's deposit
17661
+ * actually covers).
17662
+ *
17663
+ * These helpers compute the limit price a UI should pre-fill / display so that
17664
+ * an order placed at the displayed tick will actually cross now.
17665
+ */
17666
+ declare const BPS_DENOMINATOR = 10000n;
17667
+ /** Operator fee is a protocol constant, not stored per-market. */
17668
+ declare const OPERATOR_FEE_BPS = 10n;
17669
+ interface MarketFeeBps {
17670
+ protocolFeeBps: bigint;
17671
+ venueFeeBps: bigint;
17672
+ /** Defaults to {@link OPERATOR_FEE_BPS} when omitted. */
17673
+ operatorFeeBps?: bigint;
17674
+ }
17675
+ declare function getTotalFeeBps(fees: MarketFeeBps): bigint;
17676
+ interface FeeAwarePriceResult {
17677
+ tick: bigint;
17678
+ /** Decimal price string (e.g. "0.48"). */
17679
+ price: string;
17680
+ /** Which settlement path produced this crossing tick. */
17681
+ path: 'normal' | 'mint' | 'merge';
17682
+ }
17683
+ /**
17684
+ * Minimum BUY limit price that will fully cross right now.
17685
+ *
17686
+ * Considers both:
17687
+ * - Normal fill against same-outcome ask: limit ≥ ask × (1 + feeBps/10_000)
17688
+ * - Mint fill against opposite-outcome bid: limit + oppositeBid ≥ 1 × (1 + feeBps/10_000)
17689
+ *
17690
+ * Returns the cheaper of the two (rounded up to the nearest tick), or `null`
17691
+ * when there is no crossable liquidity at any feasible price.
17692
+ */
17693
+ declare function minBuyTickToCross(params: {
17694
+ sameOutcomeAskTick: bigint | null;
17695
+ oppositeOutcomeBidTick: bigint | null;
17696
+ tickSize: bigint;
17697
+ feeBps: bigint;
17698
+ }): FeeAwarePriceResult | null;
17699
+ /**
17700
+ * Maximum SELL limit price that will fully cross right now.
17701
+ *
17702
+ * Considers both:
17703
+ * - Normal fill against same-outcome bid: limit ≤ sameOutcomeBid
17704
+ * (no fee adjustment — fees come out of seller's proceeds, not the limit)
17705
+ * - Merge fill against opposite-outcome ask: limit + oppositeAsk ≤ 1 × (1 - feeBps/10_000)
17706
+ *
17707
+ * Returns the higher of the two (the most favourable sell limit that still
17708
+ * crosses), or `null` when no crossable liquidity exists.
17709
+ */
17710
+ declare function maxSellTickToCross(params: {
17711
+ sameOutcomeBidTick: bigint | null;
17712
+ oppositeOutcomeAskTick: bigint | null;
17713
+ tickSize: bigint;
17714
+ feeBps: bigint;
17715
+ }): FeeAwarePriceResult | null;
17716
+ /**
17717
+ * Bump a BUY taker's limit to cover total fees on a normal fill.
17718
+ *
17719
+ * The matching engine reduces a taker BUY's qty whenever
17720
+ * `limit < ask × (1 + totalFeeBps/10_000)`. For a market BUY UI that already
17721
+ * applies a slippage % on top of best ask, callers typically want to *also*
17722
+ * include the fee bump so the user never silently partial-fills.
17723
+ */
17724
+ declare function applyTakerFeeBuffer(askTick: bigint, feeBps: bigint, tickSize: bigint): bigint;
17725
+ /**
17726
+ * Estimate of a BUY's economics, in human-readable units.
17727
+ *
17728
+ * `pricePerShare` is expected to be the **fee-inclusive effective price** the
17729
+ * user actually pays per share (i.e. raw ask × (1 + totalFeeBps/10_000) for a
17730
+ * normal-fill taker, or the limit tick for a passive maker order). All other
17731
+ * fields fall out of that.
17732
+ */
17733
+ interface BuyOutcomeEstimate {
17734
+ /** Shares acquired. */
17735
+ shares: number;
17736
+ /** Total spent (cost basis). */
17737
+ cost: number;
17738
+ /** Total dollars received if the outcome wins (= shares, since each pays $1). */
17739
+ payout: number;
17740
+ /** Profit if the outcome wins (payout − cost). Polymarket's "To Win". */
17741
+ profit: number;
17742
+ /** Effective average price per share (the input). */
17743
+ avgPrice: number;
17744
+ }
17745
+ /** Estimate from a known shares quantity and per-share price. */
17746
+ declare function estimateBuyFromShares(shares: number, pricePerShare: number): BuyOutcomeEstimate;
17747
+ /** Estimate from a dollar amount and a fee-inclusive avg price per share. */
17748
+ declare function estimateBuyFromAmount(amount: number, pricePerShare: number): BuyOutcomeEstimate;
17749
+ /**
17750
+ * Estimate of a SELL's net proceeds.
17751
+ *
17752
+ * `pricePerShare` should be the **fee-inclusive net** the seller receives per
17753
+ * share (i.e. raw bid × (1 − totalFeeBps/10_000) when the seller is the taker).
17754
+ */
17755
+ interface SellOutcomeEstimate {
17756
+ shares: number;
17757
+ /** Effective net price per share. */
17758
+ avgPrice: number;
17759
+ /** Dollars the seller receives (= shares × avgPrice). */
17760
+ proceeds: number;
17761
+ }
17762
+ declare function estimateSellFromShares(shares: number, pricePerShare: number): SellOutcomeEstimate;
17763
+
17654
17764
  declare const version = "0.1.0";
17655
17765
 
17656
- 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_PRICE_MARKET_SERIES, 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_TRADER_VENUE_CLOSED_POSITIONS, GET_TRADER_VENUE_FILLS, GET_TRADER_VENUE_POSITIONS, GET_TRADER_VENUE_PROFILE, GET_TRADES, GET_UNIFIED_MARKET_FEED, GET_UNIFIED_MARKET_FEED_BY_VOLUME, GET_USER, GET_VENUES, GET_VENUE_LEADERBOARD, LimitOrdersFacet as LimitOrdersFacetABI, MarketGroupFacet as MarketGroupFacetABI, type MarketMetadata, MarketModule, MarketOrdersFacet as MarketOrdersFacetABI, type MarketQuestion, type MarketStatus, 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, type ProjectedOpenPrice, ProtocolFacet as ProtocolFacetABI, PublicModule, PythResolutionFacet as PythResolutionFacetABI, type PythUpdate, ResolutionFacet as ResolutionFacetABI, SUBGRAPH_IDS, SubgraphClient, type SubgraphMarketPriceData, TICK_SIZE_FINE, TICK_SIZE_STANDARD, TagsFacet as TagsFacetABI, TokenModule, type TopOfBookEntry, TradeModule, UMA_DEFAULTS, UmaModule, UmaOracle as UmaOracleABI, VALID_TICK_SIZES, VaultFacet as VaultFacetABI, VenueFacet as VenueFacetABI, type VenueMetadata, VenueModule, WhitelistAccessControl as WhitelistAccessControlABI, buildSubgraphGatewayUrl, calculateChancePercent, clearDecimalsCache, createExpiry, createOddMakiClient, formatAmount, formatAncillaryData, formatTimestamp, getCachedTokenDecimals, getOutcomePrice, getTokenDecimals, isValidTickSize, parseAmount, parseAncillaryData, parseMetadata, parseTokenAmount, priceToTick, resolveIPFSUri, tickToPercentage, tickToPrice, version };
17766
+ export { AccessControlFacet as AccessControlFacetABI, AccessControlModule, BPS_DENOMINATOR, BatchOrdersFacet as BatchOrdersFacetABI, type BuyOutcomeEstimate, CONTRACT_ADDRESSES, type ChancePercentInput, ConditionalTokens as ConditionalTokensABI, DEFAULT_CHAIN, ERC20 as ERC20ABI, type FeeAwarePriceResult, 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_PRICE_MARKET_SERIES, 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_TRADER_VENUE_CLOSED_POSITIONS, GET_TRADER_VENUE_FILLS, GET_TRADER_VENUE_POSITIONS, GET_TRADER_VENUE_PROFILE, GET_TRADES, GET_UNIFIED_MARKET_FEED, GET_UNIFIED_MARKET_FEED_BY_VOLUME, GET_USER, GET_VENUES, GET_VENUE_LEADERBOARD, LimitOrdersFacet as LimitOrdersFacetABI, type MarketFeeBps, MarketGroupFacet as MarketGroupFacetABI, type MarketMetadata, MarketModule, MarketOrdersFacet as MarketOrdersFacetABI, type MarketQuestion, type MarketStatus, MarketsFacet as MarketsFacetABI, MatchingFacet as MatchingFacetABI, MetadataFacet as MetadataFacetABI, NegRiskFacet as NegRiskFacetABI, OPERATOR_FEE_BPS, OddMakiClient, type OddMakiClientConfig, type OddMakiConfig, OrderBookFacet as OrderBookFacetABI, PROTOCOL_FEES, type PriceMarketData, PriceMarketFacet as PriceMarketFacetABI, PriceMarketModule, type ProjectedOpenPrice, ProtocolFacet as ProtocolFacetABI, PublicModule, PythResolutionFacet as PythResolutionFacetABI, type PythUpdate, ResolutionFacet as ResolutionFacetABI, SUBGRAPH_IDS, type SellOutcomeEstimate, SubgraphClient, type SubgraphMarketPriceData, TICK_SIZE_FINE, TICK_SIZE_STANDARD, TagsFacet as TagsFacetABI, TokenModule, type TopOfBookEntry, TradeModule, UMA_DEFAULTS, UmaModule, UmaOracle as UmaOracleABI, VALID_TICK_SIZES, VaultFacet as VaultFacetABI, VenueFacet as VenueFacetABI, type VenueMetadata, VenueModule, WhitelistAccessControl as WhitelistAccessControlABI, applyTakerFeeBuffer, buildSubgraphGatewayUrl, calculateChancePercent, clearDecimalsCache, createExpiry, createOddMakiClient, estimateBuyFromAmount, estimateBuyFromShares, estimateSellFromShares, formatAmount, formatAncillaryData, formatTimestamp, getCachedTokenDecimals, getOutcomePrice, getTokenDecimals, getTotalFeeBps, isValidTickSize, maxSellTickToCross, minBuyTickToCross, parseAmount, parseAncillaryData, parseMetadata, parseTokenAmount, priceToTick, resolveIPFSUri, tickToPercentage, tickToPrice, version };
package/dist/index.d.ts CHANGED
@@ -17651,6 +17651,116 @@ declare function parseMetadata<T extends {
17651
17651
  version: number;
17652
17652
  }>(json: string): T | null;
17653
17653
 
17654
+ /**
17655
+ * Fee-aware pricing helpers.
17656
+ *
17657
+ * The matching engine's mint-to-fill / merge-to-fill paths require bids/asks to
17658
+ * cover 1.0 PLUS total fees (protocol + venue + operator). Normal fills also
17659
+ * require taker buyers to bid at ask × (1 + totalFeeBps/10_000) for the full
17660
+ * quantity to fill (otherwise qty is reduced to whatever the taker's deposit
17661
+ * actually covers).
17662
+ *
17663
+ * These helpers compute the limit price a UI should pre-fill / display so that
17664
+ * an order placed at the displayed tick will actually cross now.
17665
+ */
17666
+ declare const BPS_DENOMINATOR = 10000n;
17667
+ /** Operator fee is a protocol constant, not stored per-market. */
17668
+ declare const OPERATOR_FEE_BPS = 10n;
17669
+ interface MarketFeeBps {
17670
+ protocolFeeBps: bigint;
17671
+ venueFeeBps: bigint;
17672
+ /** Defaults to {@link OPERATOR_FEE_BPS} when omitted. */
17673
+ operatorFeeBps?: bigint;
17674
+ }
17675
+ declare function getTotalFeeBps(fees: MarketFeeBps): bigint;
17676
+ interface FeeAwarePriceResult {
17677
+ tick: bigint;
17678
+ /** Decimal price string (e.g. "0.48"). */
17679
+ price: string;
17680
+ /** Which settlement path produced this crossing tick. */
17681
+ path: 'normal' | 'mint' | 'merge';
17682
+ }
17683
+ /**
17684
+ * Minimum BUY limit price that will fully cross right now.
17685
+ *
17686
+ * Considers both:
17687
+ * - Normal fill against same-outcome ask: limit ≥ ask × (1 + feeBps/10_000)
17688
+ * - Mint fill against opposite-outcome bid: limit + oppositeBid ≥ 1 × (1 + feeBps/10_000)
17689
+ *
17690
+ * Returns the cheaper of the two (rounded up to the nearest tick), or `null`
17691
+ * when there is no crossable liquidity at any feasible price.
17692
+ */
17693
+ declare function minBuyTickToCross(params: {
17694
+ sameOutcomeAskTick: bigint | null;
17695
+ oppositeOutcomeBidTick: bigint | null;
17696
+ tickSize: bigint;
17697
+ feeBps: bigint;
17698
+ }): FeeAwarePriceResult | null;
17699
+ /**
17700
+ * Maximum SELL limit price that will fully cross right now.
17701
+ *
17702
+ * Considers both:
17703
+ * - Normal fill against same-outcome bid: limit ≤ sameOutcomeBid
17704
+ * (no fee adjustment — fees come out of seller's proceeds, not the limit)
17705
+ * - Merge fill against opposite-outcome ask: limit + oppositeAsk ≤ 1 × (1 - feeBps/10_000)
17706
+ *
17707
+ * Returns the higher of the two (the most favourable sell limit that still
17708
+ * crosses), or `null` when no crossable liquidity exists.
17709
+ */
17710
+ declare function maxSellTickToCross(params: {
17711
+ sameOutcomeBidTick: bigint | null;
17712
+ oppositeOutcomeAskTick: bigint | null;
17713
+ tickSize: bigint;
17714
+ feeBps: bigint;
17715
+ }): FeeAwarePriceResult | null;
17716
+ /**
17717
+ * Bump a BUY taker's limit to cover total fees on a normal fill.
17718
+ *
17719
+ * The matching engine reduces a taker BUY's qty whenever
17720
+ * `limit < ask × (1 + totalFeeBps/10_000)`. For a market BUY UI that already
17721
+ * applies a slippage % on top of best ask, callers typically want to *also*
17722
+ * include the fee bump so the user never silently partial-fills.
17723
+ */
17724
+ declare function applyTakerFeeBuffer(askTick: bigint, feeBps: bigint, tickSize: bigint): bigint;
17725
+ /**
17726
+ * Estimate of a BUY's economics, in human-readable units.
17727
+ *
17728
+ * `pricePerShare` is expected to be the **fee-inclusive effective price** the
17729
+ * user actually pays per share (i.e. raw ask × (1 + totalFeeBps/10_000) for a
17730
+ * normal-fill taker, or the limit tick for a passive maker order). All other
17731
+ * fields fall out of that.
17732
+ */
17733
+ interface BuyOutcomeEstimate {
17734
+ /** Shares acquired. */
17735
+ shares: number;
17736
+ /** Total spent (cost basis). */
17737
+ cost: number;
17738
+ /** Total dollars received if the outcome wins (= shares, since each pays $1). */
17739
+ payout: number;
17740
+ /** Profit if the outcome wins (payout − cost). Polymarket's "To Win". */
17741
+ profit: number;
17742
+ /** Effective average price per share (the input). */
17743
+ avgPrice: number;
17744
+ }
17745
+ /** Estimate from a known shares quantity and per-share price. */
17746
+ declare function estimateBuyFromShares(shares: number, pricePerShare: number): BuyOutcomeEstimate;
17747
+ /** Estimate from a dollar amount and a fee-inclusive avg price per share. */
17748
+ declare function estimateBuyFromAmount(amount: number, pricePerShare: number): BuyOutcomeEstimate;
17749
+ /**
17750
+ * Estimate of a SELL's net proceeds.
17751
+ *
17752
+ * `pricePerShare` should be the **fee-inclusive net** the seller receives per
17753
+ * share (i.e. raw bid × (1 − totalFeeBps/10_000) when the seller is the taker).
17754
+ */
17755
+ interface SellOutcomeEstimate {
17756
+ shares: number;
17757
+ /** Effective net price per share. */
17758
+ avgPrice: number;
17759
+ /** Dollars the seller receives (= shares × avgPrice). */
17760
+ proceeds: number;
17761
+ }
17762
+ declare function estimateSellFromShares(shares: number, pricePerShare: number): SellOutcomeEstimate;
17763
+
17654
17764
  declare const version = "0.1.0";
17655
17765
 
17656
- 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_PRICE_MARKET_SERIES, 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_TRADER_VENUE_CLOSED_POSITIONS, GET_TRADER_VENUE_FILLS, GET_TRADER_VENUE_POSITIONS, GET_TRADER_VENUE_PROFILE, GET_TRADES, GET_UNIFIED_MARKET_FEED, GET_UNIFIED_MARKET_FEED_BY_VOLUME, GET_USER, GET_VENUES, GET_VENUE_LEADERBOARD, LimitOrdersFacet as LimitOrdersFacetABI, MarketGroupFacet as MarketGroupFacetABI, type MarketMetadata, MarketModule, MarketOrdersFacet as MarketOrdersFacetABI, type MarketQuestion, type MarketStatus, 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, type ProjectedOpenPrice, ProtocolFacet as ProtocolFacetABI, PublicModule, PythResolutionFacet as PythResolutionFacetABI, type PythUpdate, ResolutionFacet as ResolutionFacetABI, SUBGRAPH_IDS, SubgraphClient, type SubgraphMarketPriceData, TICK_SIZE_FINE, TICK_SIZE_STANDARD, TagsFacet as TagsFacetABI, TokenModule, type TopOfBookEntry, TradeModule, UMA_DEFAULTS, UmaModule, UmaOracle as UmaOracleABI, VALID_TICK_SIZES, VaultFacet as VaultFacetABI, VenueFacet as VenueFacetABI, type VenueMetadata, VenueModule, WhitelistAccessControl as WhitelistAccessControlABI, buildSubgraphGatewayUrl, calculateChancePercent, clearDecimalsCache, createExpiry, createOddMakiClient, formatAmount, formatAncillaryData, formatTimestamp, getCachedTokenDecimals, getOutcomePrice, getTokenDecimals, isValidTickSize, parseAmount, parseAncillaryData, parseMetadata, parseTokenAmount, priceToTick, resolveIPFSUri, tickToPercentage, tickToPrice, version };
17766
+ export { AccessControlFacet as AccessControlFacetABI, AccessControlModule, BPS_DENOMINATOR, BatchOrdersFacet as BatchOrdersFacetABI, type BuyOutcomeEstimate, CONTRACT_ADDRESSES, type ChancePercentInput, ConditionalTokens as ConditionalTokensABI, DEFAULT_CHAIN, ERC20 as ERC20ABI, type FeeAwarePriceResult, 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_PRICE_MARKET_SERIES, 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_TRADER_VENUE_CLOSED_POSITIONS, GET_TRADER_VENUE_FILLS, GET_TRADER_VENUE_POSITIONS, GET_TRADER_VENUE_PROFILE, GET_TRADES, GET_UNIFIED_MARKET_FEED, GET_UNIFIED_MARKET_FEED_BY_VOLUME, GET_USER, GET_VENUES, GET_VENUE_LEADERBOARD, LimitOrdersFacet as LimitOrdersFacetABI, type MarketFeeBps, MarketGroupFacet as MarketGroupFacetABI, type MarketMetadata, MarketModule, MarketOrdersFacet as MarketOrdersFacetABI, type MarketQuestion, type MarketStatus, MarketsFacet as MarketsFacetABI, MatchingFacet as MatchingFacetABI, MetadataFacet as MetadataFacetABI, NegRiskFacet as NegRiskFacetABI, OPERATOR_FEE_BPS, OddMakiClient, type OddMakiClientConfig, type OddMakiConfig, OrderBookFacet as OrderBookFacetABI, PROTOCOL_FEES, type PriceMarketData, PriceMarketFacet as PriceMarketFacetABI, PriceMarketModule, type ProjectedOpenPrice, ProtocolFacet as ProtocolFacetABI, PublicModule, PythResolutionFacet as PythResolutionFacetABI, type PythUpdate, ResolutionFacet as ResolutionFacetABI, SUBGRAPH_IDS, type SellOutcomeEstimate, SubgraphClient, type SubgraphMarketPriceData, TICK_SIZE_FINE, TICK_SIZE_STANDARD, TagsFacet as TagsFacetABI, TokenModule, type TopOfBookEntry, TradeModule, UMA_DEFAULTS, UmaModule, UmaOracle as UmaOracleABI, VALID_TICK_SIZES, VaultFacet as VaultFacetABI, VenueFacet as VenueFacetABI, type VenueMetadata, VenueModule, WhitelistAccessControl as WhitelistAccessControlABI, applyTakerFeeBuffer, buildSubgraphGatewayUrl, calculateChancePercent, clearDecimalsCache, createExpiry, createOddMakiClient, estimateBuyFromAmount, estimateBuyFromShares, estimateSellFromShares, formatAmount, formatAncillaryData, formatTimestamp, getCachedTokenDecimals, getOutcomePrice, getTokenDecimals, getTotalFeeBps, isValidTickSize, maxSellTickToCross, minBuyTickToCross, parseAmount, parseAncillaryData, parseMetadata, parseTokenAmount, priceToTick, resolveIPFSUri, tickToPercentage, tickToPrice, version };
package/dist/index.js CHANGED
@@ -12290,6 +12290,104 @@ function parseMetadata(json) {
12290
12290
  }
12291
12291
  }
12292
12292
 
12293
+ // src/utils/feeAwarePricing.ts
12294
+ var BPS_DENOMINATOR = 10000n;
12295
+ var OPERATOR_FEE_BPS = 10n;
12296
+ function getTotalFeeBps(fees) {
12297
+ return fees.protocolFeeBps + fees.venueFeeBps + (fees.operatorFeeBps ?? OPERATOR_FEE_BPS);
12298
+ }
12299
+ function ceilDiv(numerator, denominator) {
12300
+ return (numerator + denominator - 1n) / denominator;
12301
+ }
12302
+ function fullPriceTicks(tickSize) {
12303
+ return 10n ** 18n / tickSize;
12304
+ }
12305
+ function minBuyTickToCross(params) {
12306
+ const fullTicks = fullPriceTicks(params.tickSize);
12307
+ const minTotalTicks = ceilDiv(fullTicks * (BPS_DENOMINATOR + params.feeBps), BPS_DENOMINATOR);
12308
+ let best = null;
12309
+ if (params.sameOutcomeAskTick && params.sameOutcomeAskTick > 0n) {
12310
+ const tick = ceilDiv(
12311
+ params.sameOutcomeAskTick * (BPS_DENOMINATOR + params.feeBps),
12312
+ BPS_DENOMINATOR
12313
+ );
12314
+ if (tick > 0n && tick <= fullTicks) {
12315
+ best = { tick, price: tickToPrice(tick, params.tickSize), path: "normal" };
12316
+ }
12317
+ }
12318
+ if (params.oppositeOutcomeBidTick && params.oppositeOutcomeBidTick > 0n) {
12319
+ if (params.oppositeOutcomeBidTick < minTotalTicks) {
12320
+ const tick = minTotalTicks - params.oppositeOutcomeBidTick;
12321
+ if (tick > 0n && tick <= fullTicks) {
12322
+ if (!best || tick < best.tick) {
12323
+ best = { tick, price: tickToPrice(tick, params.tickSize), path: "mint" };
12324
+ }
12325
+ }
12326
+ }
12327
+ }
12328
+ return best;
12329
+ }
12330
+ function maxSellTickToCross(params) {
12331
+ const fullTicks = fullPriceTicks(params.tickSize);
12332
+ const maxMergeTotalTicks = fullTicks * (BPS_DENOMINATOR - params.feeBps) / BPS_DENOMINATOR;
12333
+ let best = null;
12334
+ if (params.sameOutcomeBidTick && params.sameOutcomeBidTick > 0n) {
12335
+ const tick = params.sameOutcomeBidTick;
12336
+ best = { tick, price: tickToPrice(tick, params.tickSize), path: "normal" };
12337
+ }
12338
+ if (params.oppositeOutcomeAskTick && params.oppositeOutcomeAskTick > 0n) {
12339
+ if (maxMergeTotalTicks > params.oppositeOutcomeAskTick) {
12340
+ const tick = maxMergeTotalTicks - params.oppositeOutcomeAskTick;
12341
+ if (tick > 0n && (!best || tick > best.tick)) {
12342
+ best = { tick, price: tickToPrice(tick, params.tickSize), path: "merge" };
12343
+ }
12344
+ }
12345
+ }
12346
+ return best;
12347
+ }
12348
+ function applyTakerFeeBuffer(askTick, feeBps, tickSize) {
12349
+ const fullTicks = fullPriceTicks(tickSize);
12350
+ const tick = ceilDiv(askTick * (BPS_DENOMINATOR + feeBps), BPS_DENOMINATOR);
12351
+ return tick > fullTicks ? fullTicks : tick;
12352
+ }
12353
+ function estimateBuyFromShares(shares, pricePerShare) {
12354
+ const safeShares = Math.max(0, Number.isFinite(shares) ? shares : 0);
12355
+ const safePrice = Math.max(0, Number.isFinite(pricePerShare) ? pricePerShare : 0);
12356
+ const cost = safeShares * safePrice;
12357
+ const payout = safeShares;
12358
+ return {
12359
+ shares: safeShares,
12360
+ cost,
12361
+ payout,
12362
+ profit: payout - cost,
12363
+ avgPrice: safePrice
12364
+ };
12365
+ }
12366
+ function estimateBuyFromAmount(amount, pricePerShare) {
12367
+ const safeAmount = Math.max(0, Number.isFinite(amount) ? amount : 0);
12368
+ const safePrice = Math.max(0, Number.isFinite(pricePerShare) ? pricePerShare : 0);
12369
+ if (safePrice <= 0) {
12370
+ return { shares: 0, cost: safeAmount, payout: 0, profit: -safeAmount, avgPrice: 0 };
12371
+ }
12372
+ const shares = safeAmount / safePrice;
12373
+ return {
12374
+ shares,
12375
+ cost: safeAmount,
12376
+ payout: shares,
12377
+ profit: shares - safeAmount,
12378
+ avgPrice: safePrice
12379
+ };
12380
+ }
12381
+ function estimateSellFromShares(shares, pricePerShare) {
12382
+ const safeShares = Math.max(0, Number.isFinite(shares) ? shares : 0);
12383
+ const safePrice = Math.max(0, Number.isFinite(pricePerShare) ? pricePerShare : 0);
12384
+ return {
12385
+ shares: safeShares,
12386
+ avgPrice: safePrice,
12387
+ proceeds: safeShares * safePrice
12388
+ };
12389
+ }
12390
+
12293
12391
  // src/index.ts
12294
12392
  var version = "0.1.0";
12295
12393
 
@@ -12307,6 +12405,7 @@ Object.defineProperty(exports, "gql", {
12307
12405
  });
12308
12406
  exports.AccessControlFacetABI = AccessControlFacet_default;
12309
12407
  exports.AccessControlModule = AccessControlModule;
12408
+ exports.BPS_DENOMINATOR = BPS_DENOMINATOR;
12310
12409
  exports.BatchOrdersFacetABI = BatchOrdersFacet_default;
12311
12410
  exports.CONTRACT_ADDRESSES = CONTRACT_ADDRESSES;
12312
12411
  exports.ConditionalTokensABI = ConditionalTokens_default;
@@ -12356,6 +12455,7 @@ exports.MarketsFacetABI = MarketsFacet_default;
12356
12455
  exports.MatchingFacetABI = MatchingFacet_default;
12357
12456
  exports.MetadataFacetABI = MetadataFacet_default;
12358
12457
  exports.NegRiskFacetABI = NegRiskFacet_default;
12458
+ exports.OPERATOR_FEE_BPS = OPERATOR_FEE_BPS;
12359
12459
  exports.OddMakiClient = OddMakiClient;
12360
12460
  exports.OrderBookFacetABI = OrderBookFacet_default;
12361
12461
  exports.PROTOCOL_FEES = PROTOCOL_FEES;
@@ -12380,18 +12480,25 @@ exports.VaultFacetABI = VaultFacet_default;
12380
12480
  exports.VenueFacetABI = VenueFacet_default;
12381
12481
  exports.VenueModule = VenueModule;
12382
12482
  exports.WhitelistAccessControlABI = WhitelistAccessControl_default;
12483
+ exports.applyTakerFeeBuffer = applyTakerFeeBuffer;
12383
12484
  exports.buildSubgraphGatewayUrl = buildSubgraphGatewayUrl;
12384
12485
  exports.calculateChancePercent = calculateChancePercent;
12385
12486
  exports.clearDecimalsCache = clearDecimalsCache;
12386
12487
  exports.createExpiry = createExpiry;
12387
12488
  exports.createOddMakiClient = createOddMakiClient;
12489
+ exports.estimateBuyFromAmount = estimateBuyFromAmount;
12490
+ exports.estimateBuyFromShares = estimateBuyFromShares;
12491
+ exports.estimateSellFromShares = estimateSellFromShares;
12388
12492
  exports.formatAmount = formatAmount;
12389
12493
  exports.formatAncillaryData = formatAncillaryData;
12390
12494
  exports.formatTimestamp = formatTimestamp;
12391
12495
  exports.getCachedTokenDecimals = getCachedTokenDecimals;
12392
12496
  exports.getOutcomePrice = getOutcomePrice;
12393
12497
  exports.getTokenDecimals = getTokenDecimals;
12498
+ exports.getTotalFeeBps = getTotalFeeBps;
12394
12499
  exports.isValidTickSize = isValidTickSize;
12500
+ exports.maxSellTickToCross = maxSellTickToCross;
12501
+ exports.minBuyTickToCross = minBuyTickToCross;
12395
12502
  exports.parseAmount = parseAmount;
12396
12503
  exports.parseAncillaryData = parseAncillaryData;
12397
12504
  exports.parseMetadata = parseMetadata;