@dimes-dot-fi/sdk 1.4.2 → 1.5.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 (39) hide show
  1. package/dist/{aliases-Dtl19fcM.d.cts → aliases-ByZ2DcA5.d.cts} +280 -5
  2. package/dist/{aliases-Dtl19fcM.d.ts → aliases-ByZ2DcA5.d.ts} +280 -5
  3. package/dist/{chunk-SGA6OZEU.mjs → chunk-3OPRSKCY.mjs} +18 -2
  4. package/dist/chunk-3OPRSKCY.mjs.map +1 -0
  5. package/dist/{chunk-DYPABUKC.cjs → chunk-72LTVPD2.cjs} +16 -1
  6. package/dist/chunk-72LTVPD2.cjs.map +1 -0
  7. package/dist/{chunk-BVILILIV.mjs → chunk-PZCBUVPD.mjs} +16 -1
  8. package/dist/chunk-PZCBUVPD.mjs.map +1 -0
  9. package/dist/{chunk-COSLZ5TM.cjs → chunk-Y5WQ3UWF.cjs} +21 -5
  10. package/dist/chunk-Y5WQ3UWF.cjs.map +1 -0
  11. package/dist/contract/index.cjs +13 -13
  12. package/dist/contract/index.d.cts +3 -3
  13. package/dist/contract/index.d.ts +3 -3
  14. package/dist/contract/index.mjs +1 -1
  15. package/dist/{dimes-client-DsRQSCTw.d.ts → dimes-client-B-thu7VQ.d.cts} +18 -3
  16. package/dist/{dimes-client-Bd7DE-tr.d.cts → dimes-client-CerC9mTr.d.ts} +18 -3
  17. package/dist/{dimes-error-DNcs8hsc.d.cts → dimes-error-BY5qVGZC.d.cts} +1 -1
  18. package/dist/{dimes-error-B46ZbXNX.d.ts → dimes-error-CrvPuFzB.d.ts} +1 -1
  19. package/dist/index.cjs +88 -6
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +138 -8
  22. package/dist/index.d.ts +138 -8
  23. package/dist/index.mjs +85 -3
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/{quote-BMw6RUjG.d.ts → quote-Czq3Selh.d.ts} +2 -2
  26. package/dist/{quote-IRF_hecL.d.cts → quote-quIOosIv.d.cts} +2 -2
  27. package/dist/react/index.cjs +4 -4
  28. package/dist/react/index.d.cts +3 -3
  29. package/dist/react/index.d.ts +3 -3
  30. package/dist/react/index.mjs +2 -2
  31. package/dist/{types-DTgaOUUw.d.cts → types-2bGyrtqd.d.cts} +1 -1
  32. package/dist/{types-Ct7tufPh.d.ts → types-CAuPxEwO.d.ts} +1 -1
  33. package/dist/ws/index.d.cts +3 -3
  34. package/dist/ws/index.d.ts +3 -3
  35. package/package.json +1 -1
  36. package/dist/chunk-BVILILIV.mjs.map +0 -1
  37. package/dist/chunk-COSLZ5TM.cjs.map +0 -1
  38. package/dist/chunk-DYPABUKC.cjs.map +0 -1
  39. package/dist/chunk-SGA6OZEU.mjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/utils/parse.ts","../src/utils/format.ts","../src/errors/error-messages.ts","../src/errors/dimes-error.ts"],"sourcesContent":["export type Params = Record<string, unknown> | null;\n\nexport function asNumber(value: unknown): number | null {\n if (typeof value === \"number\" && Number.isFinite(value)) {\n return value;\n }\n if (typeof value === \"string\" && value.trim() !== \"\") {\n const parsed = Number(value);\n if (Number.isFinite(parsed)) {\n return parsed;\n }\n }\n return null;\n}\n\nexport function asBigInt(value: unknown): bigint | null {\n if (typeof value === \"bigint\") {\n return value;\n }\n if (typeof value === \"string\" && /^-?\\d+$/.test(value.trim())) {\n return BigInt(value.trim());\n }\n if (typeof value === \"number\" && Number.isInteger(value)) {\n return BigInt(value);\n }\n return null;\n}\n\nexport function getParam(params: Params, key: string): unknown {\n return params ? params[key] : undefined;\n}\n","import { asNumber, asBigInt } from \"./parse\";\n\nconst BPS_PER_UNIT = 10_000;\nconst BPS_PER_PCT = 100;\nconst FRACTION_TO_PCT = 100;\nconst PIPS_PER_USD = 1_000_000n;\nconst ROUNDING_OFFSET = 5_000n;\nconst CENTS_DIVISOR = 10_000n;\nconst CENTS_PAD = 2;\n\nexport function formatLeverage(value: unknown): string | null {\n const n = asNumber(value);\n if (n === null) {\n return null;\n }\n return `${(n / BPS_PER_UNIT).toLocaleString(undefined, { maximumFractionDigits: 2 })}x`;\n}\n\nexport function formatBpsPct(value: unknown): string | null {\n const n = asNumber(value);\n if (n === null) {\n return null;\n }\n return `${(n / BPS_PER_PCT).toLocaleString(undefined, { maximumFractionDigits: 2 })}%`;\n}\n\nexport function formatFractionPct(value: unknown): string | null {\n const n = asNumber(value);\n if (n === null) {\n return null;\n }\n return `${(n * FRACTION_TO_PCT).toLocaleString(undefined, { maximumFractionDigits: 1 })}%`;\n}\n\nexport function formatPipsUsd(value: unknown): string | null {\n const big = asBigInt(value);\n if (big === null) {\n return null;\n }\n const negative = big < 0n;\n const absUnits = negative ? -big : big;\n const whole = absUnits / PIPS_PER_USD;\n const frac = absUnits % PIPS_PER_USD;\n const cents = (frac + ROUNDING_OFFSET) / CENTS_DIVISOR;\n const formatted = `$${whole.toLocaleString()}.${cents.toString().padStart(CENTS_PAD, \"0\")}`;\n return negative ? `-${formatted}` : formatted;\n}\n","import { formatLeverage, formatBpsPct, formatFractionPct, formatPipsUsd } from \"../utils/format\";\nimport { type Params, getParam } from \"../utils/parse\";\n\ntype FriendlyEntry = string | ((params: Params) => string);\n\nconst minFillBpsMaxForMessage = 5_000;\n\nconst friendlyByCode: Record<string, FriendlyEntry> = {\n invalid_evm_address: \"Invalid EVM address.\",\n invalid_solana_address: \"Invalid Solana address.\",\n invalid_string_for_chain_address: \"Invalid wallet address for the selected chain.\",\n invalid_wallet_address: \"Invalid wallet address.\",\n customer_auth_invalid_wallet_address: \"Invalid wallet address.\",\n\n unauthorized: \"Session expired. Please reconnect your wallet.\",\n forbidden: \"You do not have access to this resource.\",\n\n array_out_of_bounds: \"Internal indexing error. Please try again.\",\n batch_compute_not_available: \"Cached pricing is temporarily unavailable. Try again shortly.\",\n internal_server_error: \"Something went wrong on our side. Please try again.\",\n unexpected_error: \"Something went wrong. Please try again.\",\n provider_not_available: \"Upstream provider is unavailable. Try again shortly.\",\n request_already_in_progress: \"A previous request is still in flight. Wait for it to complete and try again.\",\n math_error: \"A numeric calculation failed. Please try again.\",\n invalid_number: \"Invalid numeric value in request.\",\n invalid_message: \"Received an invalid upstream message.\",\n invalid_filter_combination: \"That combination of filters is not supported.\",\n\n cancel_position_delay_not_elapsed: \"Cancel delay has not elapsed yet. Try again shortly.\",\n cancel_position_transaction_failed: \"Cancel transaction failed on-chain.\",\n cancel_position_not_found: \"Position not found.\",\n cancel_position_not_in_created_state: \"This position can only be cancelled before it has filled.\",\n cancel_position_not_on_polygon: \"Cancel is only supported for Polygon positions.\",\n customer_cancel_position_evm_only: \"Cancel is only supported for EVM positions.\",\n customer_cancel_position_not_cancellable: \"This position can no longer be cancelled.\",\n customer_cancel_position_not_owner: \"You do not own this position.\",\n customer_cancel_position_not_found: \"Position not found.\",\n\n circuit_breaker_price_divergence_tripped: \"Trading is temporarily paused due to price divergence. Try again shortly.\",\n\n customer_market_not_found: \"Market not found.\",\n customer_position_not_found: \"Position not found.\",\n customer_position_transactions_not_found: \"Position not found.\",\n\n close_position_transaction_failed: \"Close transaction failed on-chain.\",\n close_position_transaction_not_found: \"Close transaction not found.\",\n finalize_close_transaction_failed: \"Finalising the close transaction failed.\",\n close_no_open_position_transaction: \"No open transaction found for this position.\",\n close_no_request_close_transaction: \"No close request found for this position.\",\n close_polymarket_order_failed: \"Polymarket close order failed.\",\n close_polymarket_order_retry_failed: \"Polymarket close order failed after retries.\",\n close_position_already_closed: \"This position is already closed.\",\n close_position_has_no_tokens: \"This position has no tokens to close.\",\n close_position_not_found: \"Position not found.\",\n close_position_not_originated: \"Position has not been originated yet — nothing to close.\",\n\n exchange_order_submission_locked: \"Order submission is temporarily locked. Try again shortly.\",\n\n quote_partner_position_limit_exceeded: (params) => {\n const available = formatPipsUsd(getParam(params, \"availableCapacityUsdPips\"));\n return available\n ? `Partner position limit reached. Remaining capacity: ${available}.`\n : \"Partner position limit reached. Try a smaller size.\";\n },\n quote_user_position_limit_exceeded: (params) => {\n const available = formatPipsUsd(getParam(params, \"availableCapacityUsdPips\"));\n return available\n ? `You have reached your position limit on this market. Remaining capacity: ${available}.`\n : \"You have reached your position limit on this market.\";\n },\n quote_market_position_limit_exceeded: (params) => {\n const available = formatPipsUsd(getParam(params, \"availableCapacityUsdPips\"));\n return available\n ? `This market has reached its open-interest cap. Remaining capacity: ${available}.`\n : \"This market has reached its open-interest cap. Try a smaller size or another market.\";\n },\n quote_global_position_limit_exceeded: (params) => {\n const available = formatPipsUsd(getParam(params, \"availableCapacityUsdPips\"));\n return available\n ? `Global position limit reached. Remaining capacity: ${available}.`\n : \"Global position limit reached. Try again shortly.\";\n },\n quote_side_position_limit_exceeded: (params) => {\n const available = formatPipsUsd(getParam(params, \"availableCapacityUsdPips\"));\n return available\n ? `This side of the market is at its position limit. Remaining capacity: ${available}.`\n : \"This side of the market is at its position limit. Try the other side or a smaller size.\";\n },\n quote_side_capacity_exceeded: (params) => {\n const maxCollateral = formatPipsUsd(getParam(params, \"maxSupportedCollateralUsdPips\"));\n return maxCollateral\n ? `Not enough capacity on this side of the market. Max supported collateral at this size: ${maxCollateral}.`\n : \"Not enough capacity on this side of the market for that size.\";\n },\n quote_position_limit_exceeded: \"Position limit reached for this request.\",\n\n quote_insufficient_liquidity: \"Not enough liquidity on the order book to fill this size.\",\n quote_slippage_too_high: (params) => {\n const max = formatBpsPct(getParam(params, \"maxSlippageBps\"));\n const current = formatBpsPct(getParam(params, \"currentSlippageBps\"));\n if (max && current) {\n return `Required slippage ${current} exceeds your tolerance (${max}). Reduce size or raise tolerance.`;\n }\n if (max) {\n return `Required slippage exceeds your tolerance (${max}). Reduce size or raise tolerance.`;\n }\n return \"Price would move too far to fill this order. Reduce size or raise your slippage tolerance.\";\n },\n quote_event_not_started: \"This event has not started yet. Trading opens at the scheduled start time.\",\n quote_entry_bid_depth_too_low: \"Order book depth on the entry side is too thin to open this position safely.\",\n quote_entry_capacity_exceeded: \"Entry size exceeds the market's available capacity.\",\n quote_entry_depth_too_low: \"Order book depth is too thin to open this position safely.\",\n quote_entry_spread_too_wide: \"Bid/ask spread is too wide to open right now. Try again shortly.\",\n quote_entry_order_book_stale: \"Order book data is stale. Refresh and try again.\",\n quote_entry_price_stale: \"Price data is stale. Refresh and try again.\",\n quote_entry_crypto_price_stale: \"Crypto price data is stale. Refresh and try again.\",\n quote_entry_sport_data_stale: \"Sport event data is stale. Refresh and try again.\",\n quote_entry_volume_too_low: \"Recent traded volume on this market is too low to open new positions.\",\n quote_entry_top_holder_too_high: \"A single trader holds too much of this market. Opening here is restricted.\",\n quote_entry_price_out_of_range: \"Current price is outside the range we can open at. Try again shortly.\",\n quote_entry_exit_drop_too_high: \"Exit liquidity is too thin to safely open this size.\",\n quote_entry_market_too_elapsed: (params) => {\n const elapsed = formatFractionPct(getParam(params, \"pctElapsed\"));\n const max = formatFractionPct(getParam(params, \"maxPctElapsed\"));\n if (elapsed && max) {\n return `Market is ${elapsed} elapsed (max ${max}). Too close to resolution to open new positions.`;\n }\n return \"Market is too close to resolution to open new positions.\";\n },\n quote_entry_excluded_market_type: \"This market type is not supported for leveraged positions.\",\n quote_entry_excluded_sport: \"This sport is not supported for leveraged positions.\",\n quote_price_too_low: \"Underlying price is too low to open a leveraged position.\",\n quote_open_interest_unavailable: \"Open-interest data is unavailable right now. Try again shortly.\",\n\n quote_leverage_below_minimum: (params) => {\n const min = formatLeverage(getParam(params, \"minLeverageBps\"));\n const current = formatLeverage(getParam(params, \"currentLeverageBps\"));\n if (min && current) {\n return `Leverage ${current} is below the minimum allowed (${min}).`;\n }\n if (min) {\n return `Leverage is below the minimum allowed (${min}).`;\n }\n return \"Leverage is below the minimum allowed for this market.\";\n },\n quote_leverage_exceeds_maximum: (params) => {\n const max = formatLeverage(getParam(params, \"maxLeverageBps\"));\n const current = formatLeverage(getParam(params, \"currentLeverageBps\"));\n if (max && current) {\n return `Leverage ${current} is above the maximum allowed (${max}).`;\n }\n if (max) {\n return `Leverage is above the maximum allowed (${max}).`;\n }\n return \"Leverage is above the maximum allowed for this market.\";\n },\n quote_leverage_exceeds_collateral_floor: (params) => {\n const min = formatPipsUsd(getParam(params, \"minCollateralUsdPips\"));\n const current = formatPipsUsd(getParam(params, \"currentCollateralUsdPips\"));\n if (min && current) {\n return `Collateral ${current} is below the minimum ${min} required at this leverage. Raise collateral to at least ${min}.`;\n }\n if (min) {\n return `Collateral is below the minimum ${min} required at this leverage. Raise collateral to at least ${min}.`;\n }\n return \"Collateral is below the minimum required at this leverage. Raise collateral.\";\n },\n quote_leverage_exceeds_model_max: (params) => {\n const max = formatLeverage(getParam(params, \"maxLeverageBps\"));\n const current = formatLeverage(getParam(params, \"currentLeverageBps\"));\n if (max && current) {\n return `Leverage ${current} exceeds the risk-model limit (${max}) for this market.`;\n }\n if (max) {\n return `Leverage exceeds the risk-model limit (${max}) for this market.`;\n }\n return \"Leverage exceeds the risk-model limit for this market.\";\n },\n quote_leverage_too_high_for_price: (params) => {\n const current = formatLeverage(getParam(params, \"currentLeverageBps\"));\n const max = formatLeverage(getParam(params, \"maxAcceptableLeverageBps\"));\n if (current && max) {\n return `Leverage ${current} is too high for the current price. Maximum is ${max}.`;\n }\n if (current) {\n return `Leverage ${current} is too high for the current price. Reduce leverage.`;\n }\n return \"Leverage is too high for the current price. Reduce leverage.\";\n },\n quote_trading_window_closing: \"Trading window is closing. Reduce leverage.\",\n quote_hard_exit_too_close: \"Trading window is closing. Reduce leverage.\",\n quote_liquidation_not_viable: (params) => {\n const tolerance = formatBpsPct(getParam(params, \"minTolerancePctBps\"));\n return tolerance\n ? `Liquidation price is too close to entry (minimum buffer ${tolerance}). Reduce leverage.`\n : \"Liquidation price is not viable at this leverage. Reduce leverage.\";\n },\n\n quote_min_fill_bps_requires_fak: \"Partial-fill request was malformed. Please re-quote.\",\n quote_min_fill_bps_out_of_range: \"Minimum fill must be between 20% and 50%.\",\n quote_min_fill_bps_step_invalid: \"Minimum fill must be set in 5% steps.\",\n quote_min_fill_bps_below_floor: (params) => {\n const floorRaw = getParam(params, \"floorMinFillBps\");\n const floorPct = formatBpsPct(floorRaw);\n const limit = getParam(params, \"boundBy\") === \"notional\" ? \"minimum order size\" : \"minimum collateral\";\n const floorBeyondMax = typeof floorRaw === \"number\" && floorRaw > minFillBpsMaxForMessage;\n if (floorBeyondMax || !floorPct) {\n return `This trade is too small for a partial fill without falling below the ${limit}. Increase your trade size, or turn off partial fill to open atomically.`;\n }\n return `This trade is too small for that minimum fill — a partial fill could fall below the ${limit}. Raise the minimum fill to at least ${floorPct}, or increase your trade size.`;\n },\n quote_fak_order_type_disabled: \"Partial fills are temporarily unavailable. Turn off partial fill to continue.\",\n\n quote_market_not_active: \"Market is not active.\",\n quote_market_not_eligible: \"Market is not eligible for leveraged trading.\",\n quote_market_not_ready: \"Market is not ready yet. Try again shortly.\",\n quote_market_not_found: \"Market not found.\",\n quote_market_risk_too_high: \"Market risk is too high right now. Try again later.\",\n quote_market_unsupported_category: \"This market category is not supported.\",\n quote_market_no_prices: \"No price data available for this market.\",\n quote_market_missing_polymarket_condition_id: \"This market is missing required Polymarket data.\",\n\n quote_polymarket_market_closed: \"This Polymarket market is closed and not accepting new positions.\",\n quote_polymarket_market_inactive: \"This Polymarket market is inactive and not accepting new positions.\",\n quote_polymarket_market_not_accepting_orders:\n \"Polymarket is not accepting orders on this market right now. Try again shortly or pick another market.\",\n quote_polymarket_missing_token: \"This Polymarket market is missing a tradable outcome token.\",\n quote_invalid_polymarket_wallet_address: \"Invalid Polymarket wallet address.\",\n quote_invalid_kalshi_wallet_address: \"Invalid Kalshi wallet address.\",\n\n kalshi_quote_market_closed: \"This Kalshi market is closed.\",\n\n quote_draft_not_found: \"This quote has expired or does not exist. Please request a new quote.\",\n\n quote_twap_data_stale: \"Reference price (TWAP) is stale. Try again shortly.\",\n quote_twap_data_unavailable: \"Reference price (TWAP) is unavailable for this market.\",\n quote_revision_required: \"Quote needs to be refreshed before submitting.\",\n quote_price_provider_not_found: \"No price provider configured for this market.\",\n\n notional_selector_insufficient_liquidity: \"Not enough liquidity at the selected size.\",\n\n evm_gas_price_circuit_breaker: \"EVM gas price is too high — trading is temporarily paused.\",\n evm_gas_price_spike: \"EVM gas price spiked. Try again shortly.\",\n evm_simulation_failed: \"Transaction simulation failed. The transaction would revert on-chain.\",\n evm_receipt_timeout: \"Transaction confirmation timed out. Check status before retrying.\",\n evm_transaction_failed: \"EVM transaction failed.\",\n\n position_transition_conflicting_operation: \"Another operation on this position is in progress. Try again shortly.\",\n position_transition_invalid_state: \"Position is not in a state that allows this action.\",\n\n quote_creation_disabled: \"Quote creation is temporarily disabled. Try again shortly.\",\n};\n\nfunction humanizeCode(code: string): string {\n const spaced = code.replace(/_/g, \" \");\n return spaced.charAt(0).toUpperCase() + spaced.slice(1);\n}\n\nexport function resolveFriendlyMessage(code: string, params: Params): string | null {\n const entry = friendlyByCode[code];\n if (entry === undefined) {\n return null;\n }\n return typeof entry === \"function\" ? entry(params) : entry;\n}\n\nexport function formatErrorMessage(code: string, params: Params): string {\n return resolveFriendlyMessage(code, params) ?? humanizeCode(code);\n}\n","import type { QuoteHint } from \"../quote/quote-error-hints\";\nimport { resolveFriendlyMessage } from \"./error-messages\";\n\nexport class DimesError extends Error {\n public readonly code: string;\n\n constructor(code: string, message: string) {\n super(message);\n this.name = \"DimesError\";\n this.code = code;\n }\n}\n\nexport class DimesApiError extends DimesError {\n public readonly status: number;\n\n public readonly type: string | null;\n\n public readonly rawMessage: string;\n\n public readonly params: Record<string, unknown> | null;\n\n public readonly hint: QuoteHint | null;\n\n constructor(options: {\n status: number;\n code: string;\n type: string | null;\n message: string;\n params: Record<string, unknown> | null;\n hint?: QuoteHint | null;\n }) {\n const friendly = resolveFriendlyMessage(options.code, options.params) ?? options.message;\n super(options.code, friendly);\n this.name = \"DimesApiError\";\n this.status = options.status;\n this.type = options.type;\n this.rawMessage = options.message;\n this.params = options.params;\n this.hint = options.hint ?? null;\n }\n}\n\nexport class DimesContractError extends DimesError {\n constructor(code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SAAS,mBAAmB,MAAc,QAAwB;AACvE,SAAO,uBAAuB,MAAM,MAAM,KAAK,aAAa,IAAI;AAClE;;;ACzQO,IAAM,aAAN,cAAyB,MAAM;AAAA,EACpB;AAAA,EAEhB,YAAY,MAAc,SAAiB;AACzC,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,gBAAN,cAA4B,WAAW;AAAA,EAC5B;AAAA,EAEA;AAAA,EAEA;AAAA,EAEA;AAAA,EAEA;AAAA,EAEhB,YAAY,SAOT;AACD,UAAM,WAAW,uBAAuB,QAAQ,MAAM,QAAQ,MAAM,KAAK,QAAQ;AACjF,UAAM,QAAQ,MAAM,QAAQ;AAC5B,SAAK,OAAO;AACZ,SAAK,SAAS,QAAQ;AACtB,SAAK,OAAO,QAAQ;AACpB,SAAK,aAAa,QAAQ;AAC1B,SAAK,SAAS,QAAQ;AACtB,SAAK,OAAO,QAAQ,QAAQ;AAAA,EAC9B;AACF;AAEO,IAAM,qBAAN,cAAiC,WAAW;AAAA,EACjD,YAAY,MAAc,SAAiB;AACzC,UAAM,MAAM,OAAO;AACnB,SAAK,OAAO;AAAA,EACd;AACF;","names":[]}
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
3
 
4
- var _chunkDYPABUKCcjs = require('./chunk-DYPABUKC.cjs');
4
+ var _chunk72LTVPD2cjs = require('./chunk-72LTVPD2.cjs');
5
5
 
6
6
  // src/quote/build-quote-params.ts
7
7
  var DEFAULT_LEVERAGE_STEP_BPS = 2500;
@@ -21,6 +21,7 @@ function buildQuoteParams(params, stepBps = DEFAULT_LEVERAGE_STEP_BPS) {
21
21
  var pipsPerUsd = 1e4;
22
22
  var bpsPerUnit = 1e4;
23
23
  var bpsPerPct = 100;
24
+ var minFillBpsMax = 5e3;
24
25
  var centsFactor = 100;
25
26
  var decimalPlaces = 2;
26
27
  var marketMovedCodes = /* @__PURE__ */ new Set([
@@ -118,6 +119,13 @@ function quoteErrorHint(code, params, context) {
118
119
  }
119
120
  return { kind: "raise-leverage", minLeverageBps };
120
121
  }
122
+ case "quote_min_fill_bps_below_floor": {
123
+ const floorMinFillBps = num(params, "floorMinFillBps");
124
+ if (floorMinFillBps === null || floorMinFillBps > minFillBpsMax) {
125
+ return null;
126
+ }
127
+ return { kind: "raise-min-fill", minFillBps: floorMinFillBps };
128
+ }
121
129
  case "quote_slippage_too_high": {
122
130
  const currentSlippageBps = num(params, "currentSlippageBps");
123
131
  const maxSlippageBps = num(params, "maxSlippageBps");
@@ -200,6 +208,14 @@ function hintAdjustment(hint, current) {
200
208
  toLabel: `${(hint.maxSlippageBps / bpsPerPct).toFixed(decimalPlaces).replace(/\.?0+$/, "")}%`,
201
209
  reason: "raise-slippage"
202
210
  };
211
+ case "raise-min-fill":
212
+ return {
213
+ field: "minFill",
214
+ fromValue: _nullishCoalesce(current.minFillBps, () => ( 0)),
215
+ toValue: hint.minFillBps,
216
+ toLabel: `${(hint.minFillBps / bpsPerPct).toFixed(decimalPlaces).replace(/\.?0+$/, "")}%`,
217
+ reason: "raise-min-fill"
218
+ };
203
219
  default:
204
220
  return null;
205
221
  }
@@ -208,7 +224,7 @@ function hintAdjustment(hint, current) {
208
224
  // src/quote/quote.ts
209
225
  var DEFAULT_MAX_RETRIES = 3;
210
226
  function isMarketMovedError(err) {
211
- return err instanceof _chunkDYPABUKCcjs.DimesApiError && marketMovedCodes.has(err.code);
227
+ return err instanceof _chunk72LTVPD2cjs.DimesApiError && marketMovedCodes.has(err.code);
212
228
  }
213
229
  function applyAdjustment(params, adj, currentParams) {
214
230
  switch (adj.field) {
@@ -234,7 +250,7 @@ function handleMarketMoved(err, attempt, maxRetries) {
234
250
  return isMarketMovedError(err) && attempt < maxRetries;
235
251
  }
236
252
  function handleCorrection(err, currentParams) {
237
- if (!(err instanceof _chunkDYPABUKCcjs.DimesApiError)) {
253
+ if (!(err instanceof _chunk72LTVPD2cjs.DimesApiError)) {
238
254
  return null;
239
255
  }
240
256
  const hint = quoteErrorHint(err.code, err.params, {
@@ -295,7 +311,7 @@ async function executeQuote(client, params, options) {
295
311
  throw err;
296
312
  }
297
313
  }
298
- throw new (0, _chunkDYPABUKCcjs.DimesError)("market_moved_retries_exhausted", "Exhausted market-moved retries");
314
+ throw new (0, _chunk72LTVPD2cjs.DimesError)("market_moved_retries_exhausted", "Exhausted market-moved retries");
299
315
  }
300
316
 
301
317
 
@@ -305,4 +321,4 @@ async function executeQuote(client, params, options) {
305
321
 
306
322
 
307
323
  exports.buildQuoteParams = buildQuoteParams; exports.marketMovedCodes = marketMovedCodes; exports.quoteErrorHint = quoteErrorHint; exports.hintAdjustment = hintAdjustment; exports.executeQuote = executeQuote;
308
- //# sourceMappingURL=chunk-COSLZ5TM.cjs.map
324
+ //# sourceMappingURL=chunk-Y5WQ3UWF.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/alexemery/bl/dimes-sdk/dist/chunk-Y5WQ3UWF.cjs","../src/quote/build-quote-params.ts","../src/quote/quote-error-hints.ts","../src/quote/quote.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACFA,IAAM,0BAAA,EAA4B,IAAA;AAE3B,SAAS,gBAAA,CAAiB,MAAA,EAAqB,QAAA,EAAkB,yBAAA,EAA8C;AACpH,EAAA,MAAM,YAAA,EAAc,IAAA,CAAK,KAAA,CAAM,MAA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YAAA;AACF,UAAA;AAEA,UAAA;AACA,UAAA;AAEA,UAAA;AACA,UAAA;AACF,QAAA;AACF,MAAA;AAEA,MAAA;AACF,IAAA;AACF,EAAA;AAEM,EAAA;AACR;AHsLU;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/alexemery/bl/dimes-sdk/dist/chunk-Y5WQ3UWF.cjs","sourcesContent":[null,"import type { CreateOfferParams } from \"../types\";\nimport type { QuoteParams } from \"../types/quote\";\n\nconst DEFAULT_LEVERAGE_STEP_BPS = 2500;\n\nexport function buildQuoteParams(params: QuoteParams, stepBps: number = DEFAULT_LEVERAGE_STEP_BPS): CreateOfferParams {\n const leverageBps = Math.round(params.leverageBps / stepBps) * stepBps;\n const notionalUsdPips = Math.round(params.collateralUsd * leverageBps);\n\n return {\n marketTicker: params.marketTicker,\n effectiveSide: params.side,\n leverageBps,\n notionalAmountUsdPips: notionalUsdPips.toString(),\n slippageBps: params.slippageBps,\n };\n}\n","const pipsPerUsd = 10_000;\nconst bpsPerUnit = 10_000;\nconst bpsPerPct = 100;\nconst minFillBpsMax = 5_000;\nconst centsFactor = 100;\nconst decimalPlaces = 2;\n\nexport const marketMovedCodes = new Set([\n \"quote_slippage_too_high\",\n \"quote_insufficient_liquidity\",\n \"quote_entry_price_out_of_range\",\n \"quote_entry_bid_depth_too_low\",\n \"quote_entry_depth_too_low\",\n \"quote_entry_spread_too_wide\",\n]);\n\nexport type QuoteHint =\n | { kind: \"use-max-collateral\"; maxCollateralUsd: number; minCollateralUsd: number }\n | { kind: \"raise-collateral\"; minCollateralUsd: number }\n | { kind: \"clamp-leverage\"; maxLeverageBps?: number }\n | { kind: \"raise-leverage\"; minLeverageBps: number }\n | { kind: \"raise-slippage\"; currentSlippageBps: number; maxSlippageBps: number }\n | { kind: \"raise-min-fill\"; minFillBps: number }\n | { kind: \"market-full\" }\n | { kind: \"insufficient-liquidity\"; maxCollateralUsd: number; minCollateralUsd: number }\n | null;\n\ntype Params = Record<string, unknown> | null | undefined;\n\nfunction num(params: Params, key: string): number | null {\n if (!params) {\n return null;\n }\n const raw = params[key];\n if (raw === null || raw === undefined) {\n return null;\n }\n // eslint-disable-next-line no-restricted-syntax\n const n = typeof raw === \"string\" ? Number(raw) : typeof raw === \"number\" ? raw : NaN;\n return Number.isFinite(n) ? n : null;\n}\n\nfunction pipsToUsd(pips: number): number {\n return pips / pipsPerUsd;\n}\n\nfunction notionalPipsToCollateralUsd(notionalPips: number, leverageBps: number): number | null {\n if (!Number.isFinite(leverageBps) || leverageBps <= 0) {\n return null;\n }\n return (notionalPips * bpsPerUnit) / leverageBps / pipsPerUsd;\n}\n\nfunction buildExhaustedHint(\n exhaustedKind: \"market-full\" | \"insufficient-liquidity\",\n maxCollateralUsd: number,\n minCollateralUsd: number,\n): QuoteHint {\n if (exhaustedKind === \"insufficient-liquidity\") {\n return { kind: \"insufficient-liquidity\", maxCollateralUsd, minCollateralUsd };\n }\n return { kind: \"market-full\" };\n}\n\nfunction resolveMaxCollateralHint(\n params: Params,\n context: { leverageBps: number },\n capacityKey: string,\n exhaustedKind: \"market-full\" | \"insufficient-liquidity\",\n): QuoteHint {\n const serverMaxCollateralPips = num(params, \"maxSupportedCollateralUsdPips\");\n const capacityPips = num(params, capacityKey);\n const minNotionalPips = num(params, \"minNotionalUsdPips\");\n\n const fromServer = serverMaxCollateralPips !== null ? pipsToUsd(serverMaxCollateralPips) : null;\n const fromCapacity = capacityPips !== null ? notionalPipsToCollateralUsd(capacityPips, context.leverageBps) : null;\n const maxCollateralUsd =\n fromServer !== null && fromCapacity !== null ? Math.min(fromServer, fromCapacity) : (fromServer ?? fromCapacity);\n\n const minCollateralUsd =\n minNotionalPips !== null ? notionalPipsToCollateralUsd(minNotionalPips, context.leverageBps) : null;\n\n if (maxCollateralUsd === null || minCollateralUsd === null) {\n return null;\n }\n if (maxCollateralUsd < minCollateralUsd) {\n return buildExhaustedHint(exhaustedKind, maxCollateralUsd, minCollateralUsd);\n }\n return { kind: \"use-max-collateral\", maxCollateralUsd, minCollateralUsd };\n}\n\n// eslint-disable-next-line complexity\nexport function quoteErrorHint(code: string | null, params: Params, context: { leverageBps: number }): QuoteHint {\n if (!code) {\n return null;\n }\n\n switch (code) {\n case \"quote_side_capacity_exceeded\":\n case \"quote_user_position_limit_exceeded\":\n case \"quote_market_position_limit_exceeded\":\n case \"quote_side_position_limit_exceeded\":\n case \"quote_global_position_limit_exceeded\":\n case \"quote_partner_position_limit_exceeded\":\n return resolveMaxCollateralHint(params, context, \"availableCapacityUsdPips\", \"market-full\");\n\n case \"quote_insufficient_liquidity\":\n return resolveMaxCollateralHint(params, context, \"slippageMaxUsdPips\", \"market-full\");\n\n case \"notional_selector_insufficient_liquidity\":\n return resolveMaxCollateralHint(params, context, \"slippageMaxUsdPips\", \"insufficient-liquidity\");\n\n case \"quote_leverage_exceeds_collateral_floor\": {\n const minCollateralPips = num(params, \"minCollateralUsdPips\");\n if (minCollateralPips === null) {\n return null;\n }\n return { kind: \"raise-collateral\", minCollateralUsd: pipsToUsd(minCollateralPips) };\n }\n\n case \"quote_leverage_exceeds_maximum\":\n case \"quote_leverage_exceeds_model_max\": {\n const maxLeverageBps = num(params, \"maxLeverageBps\");\n if (maxLeverageBps === null) {\n return null;\n }\n return { kind: \"clamp-leverage\", maxLeverageBps };\n }\n\n case \"quote_leverage_too_high_for_price\": {\n const maxLeverageBps = num(params, \"maxAcceptableLeverageBps\");\n if (maxLeverageBps === null) {\n return null;\n }\n return { kind: \"clamp-leverage\", maxLeverageBps };\n }\n\n case \"quote_leverage_below_minimum\": {\n const minLeverageBps = num(params, \"minLeverageBps\");\n if (minLeverageBps === null) {\n return null;\n }\n return { kind: \"raise-leverage\", minLeverageBps };\n }\n\n case \"quote_min_fill_bps_below_floor\": {\n const floorMinFillBps = num(params, \"floorMinFillBps\");\n if (floorMinFillBps === null || floorMinFillBps > minFillBpsMax) {\n return null;\n }\n return { kind: \"raise-min-fill\", minFillBps: floorMinFillBps };\n }\n\n case \"quote_slippage_too_high\": {\n const currentSlippageBps = num(params, \"currentSlippageBps\");\n const maxSlippageBps = num(params, \"maxSlippageBps\");\n if (currentSlippageBps === null || maxSlippageBps === null) {\n return null;\n }\n return { kind: \"raise-slippage\", currentSlippageBps, maxSlippageBps };\n }\n\n default:\n return null;\n }\n}\n\nexport type CorrectedField = \"collateral\" | \"leverage\" | \"slippage\" | \"minFill\";\n\nexport type HintAdjustment =\n | {\n field: \"collateral\";\n fromValue: number;\n toValue: number;\n toLabel: string;\n reason: \"max-collateral\" | \"min-collateral\";\n }\n | {\n field: \"leverage\";\n fromValue: number;\n toValue: number;\n toLabel: string;\n reason: \"clamp-max\" | \"raise-min\";\n }\n | {\n field: \"slippage\";\n fromValue: number;\n toValue: number;\n toLabel: string;\n reason: \"raise-slippage\";\n }\n | {\n field: \"minFill\";\n fromValue: number;\n toValue: number;\n toLabel: string;\n reason: \"raise-min-fill\";\n }\n | null;\n\nfunction formatUsd(value: number): string {\n return new Intl.NumberFormat(\"en-US\", {\n style: \"currency\",\n currency: \"USD\",\n minimumFractionDigits: 2,\n maximumFractionDigits: 2,\n }).format(value);\n}\n\nfunction bpsToMultiplier(bps: number): string {\n return `${(bps / bpsPerUnit).toFixed(1).replace(/\\.0$/, \"\")}x`;\n}\n\n// eslint-disable-next-line complexity\nexport function hintAdjustment(\n hint: QuoteHint,\n current: { collateralUsd: number; leverageBps: number; slippageBps: number; minFillBps?: number },\n): HintAdjustment {\n if (!hint) {\n return null;\n }\n\n switch (hint.kind) {\n case \"use-max-collateral\": {\n const to = Math.max(0, Math.floor(hint.maxCollateralUsd * centsFactor) / centsFactor);\n if (to <= 0) {\n return null;\n }\n return {\n field: \"collateral\",\n fromValue: current.collateralUsd,\n toValue: to,\n toLabel: formatUsd(to),\n reason: \"max-collateral\",\n };\n }\n case \"raise-collateral\": {\n const to = Math.ceil(hint.minCollateralUsd * centsFactor) / centsFactor;\n if (to <= 0) {\n return null;\n }\n return {\n field: \"collateral\",\n fromValue: current.collateralUsd,\n toValue: to,\n toLabel: formatUsd(to),\n reason: \"min-collateral\",\n };\n }\n case \"clamp-leverage\": {\n if (hint.maxLeverageBps === undefined) {\n return null;\n }\n return {\n field: \"leverage\",\n fromValue: current.leverageBps,\n toValue: hint.maxLeverageBps,\n toLabel: bpsToMultiplier(hint.maxLeverageBps),\n reason: \"clamp-max\",\n };\n }\n case \"raise-leverage\":\n return {\n field: \"leverage\",\n fromValue: current.leverageBps,\n toValue: hint.minLeverageBps,\n toLabel: bpsToMultiplier(hint.minLeverageBps),\n reason: \"raise-min\",\n };\n case \"raise-slippage\":\n return {\n field: \"slippage\",\n fromValue: hint.currentSlippageBps,\n toValue: hint.maxSlippageBps,\n toLabel: `${(hint.maxSlippageBps / bpsPerPct).toFixed(decimalPlaces).replace(/\\.?0+$/, \"\")}%`,\n reason: \"raise-slippage\",\n };\n case \"raise-min-fill\":\n return {\n field: \"minFill\",\n fromValue: current.minFillBps ?? 0,\n toValue: hint.minFillBps,\n toLabel: `${(hint.minFillBps / bpsPerPct).toFixed(decimalPlaces).replace(/\\.?0+$/, \"\")}%`,\n reason: \"raise-min-fill\",\n };\n default:\n return null;\n }\n}\n","import { DimesApiError, DimesError } from \"../errors/dimes-error\";\nimport type { CreateOfferParams, Offer } from \"../types\";\nimport type { QuoteOptions, QuoteParams, QuoteResult } from \"../types/quote\";\nimport { buildQuoteParams } from \"./build-quote-params\";\nimport { type HintAdjustment, hintAdjustment, marketMovedCodes, quoteErrorHint } from \"./quote-error-hints\";\n\nexport interface QuoteClient {\n createDraftQuote(params: CreateOfferParams): Promise<Offer>;\n promoteDraftQuote(draftId: string): Promise<Offer>;\n createQuote(params: CreateOfferParams): Promise<Offer>;\n}\n\nconst DEFAULT_MAX_RETRIES = 3;\n\nfunction isMarketMovedError(err: unknown): boolean {\n return err instanceof DimesApiError && marketMovedCodes.has(err.code);\n}\n\nfunction applyAdjustment(\n params: CreateOfferParams,\n adj: NonNullable<HintAdjustment>,\n currentParams: QuoteParams,\n): CreateOfferParams {\n switch (adj.field) {\n case \"collateral\": {\n const notionalUsdPips = Math.round(adj.toValue * params.leverageBps);\n return { ...params, notionalAmountUsdPips: notionalUsdPips.toString() };\n }\n case \"leverage\": {\n const notionalUsdPips = Math.round(currentParams.collateralUsd * adj.toValue);\n return {\n ...params,\n leverageBps: adj.toValue,\n notionalAmountUsdPips: notionalUsdPips.toString(),\n };\n }\n case \"slippage\":\n return { ...params, slippageBps: adj.toValue };\n default:\n return params;\n }\n}\n\nfunction handleMarketMoved(err: unknown, attempt: number, maxRetries: number): boolean {\n return isMarketMovedError(err) && attempt < maxRetries;\n}\n\nfunction handleCorrection(err: unknown, currentParams: QuoteParams): { adj: NonNullable<HintAdjustment> } | null {\n if (!(err instanceof DimesApiError)) {\n return null;\n }\n\n const hint = quoteErrorHint(err.code, err.params, {\n leverageBps: currentParams.leverageBps,\n });\n\n const adj = hintAdjustment(hint, {\n collateralUsd: currentParams.collateralUsd,\n leverageBps: currentParams.leverageBps,\n slippageBps: currentParams.slippageBps,\n });\n\n if (!adj) {\n return null;\n }\n\n return { adj };\n}\n\n// eslint-disable-next-line complexity\nexport async function executeQuote(\n client: QuoteClient,\n params: QuoteParams,\n options?: QuoteOptions,\n): Promise<QuoteResult> {\n const maxRetries = options?.maxRetries ?? DEFAULT_MAX_RETRIES;\n const autoCorrect = options?.autoCorrect ?? true;\n const corrections: NonNullable<HintAdjustment>[] = [];\n let retries = 0;\n\n let offerParams = buildQuoteParams(params);\n const currentParams = { ...params };\n\n const draft = await client.createDraftQuote(offerParams);\n options?.onDraftReady?.(draft);\n\n let currentDraft: Offer = draft;\n\n for (let attempt = 0; attempt <= maxRetries; attempt++) {\n try {\n const promotedOffer = await client.promoteDraftQuote(currentDraft.id);\n return { offer: promotedOffer, corrections, retries };\n } catch (err) {\n if (handleMarketMoved(err, attempt, maxRetries)) {\n const newDraft = await client.createDraftQuote(offerParams);\n retries++;\n\n const callbackResult = options?.onMarketMoved?.({\n originalDraft: currentDraft,\n newDraft,\n retryCount: retries,\n });\n\n if (callbackResult === false) {\n throw err;\n }\n\n currentDraft = newDraft;\n continue;\n }\n\n if (autoCorrect) {\n const correction = handleCorrection(err, currentParams);\n\n if (correction) {\n const callbackResult = options?.onCorrection?.(correction.adj);\n if (callbackResult === false) {\n throw err;\n }\n\n offerParams = applyAdjustment(offerParams, correction.adj, currentParams);\n corrections.push(correction.adj);\n\n const correctedOffer = await client.createQuote(offerParams);\n return { offer: correctedOffer, corrections, retries };\n }\n }\n\n throw err;\n }\n }\n\n throw new DimesError(\"market_moved_retries_exhausted\", \"Exhausted market-moved retries\");\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
2
 
3
3
 
4
- var _chunkDYPABUKCcjs = require('../chunk-DYPABUKC.cjs');
4
+ var _chunk72LTVPD2cjs = require('../chunk-72LTVPD2.cjs');
5
5
 
6
6
  // src/contract/vault-abi.json
7
7
  var vault_abi_default = {
@@ -411,7 +411,7 @@ var _viem = require('viem');
411
411
  function toHex(value) {
412
412
  if (!_viem.isHex.call(void 0, value)) {
413
413
  const HEX_PREVIEW_LENGTH = 10;
414
- throw new (0, _chunkDYPABUKCcjs.DimesError)(
414
+ throw new (0, _chunk72LTVPD2cjs.DimesError)(
415
415
  "invalid_hex",
416
416
  `Expected hex string starting with 0x, got: ${value.slice(0, HEX_PREVIEW_LENGTH)}`
417
417
  );
@@ -420,7 +420,7 @@ function toHex(value) {
420
420
  }
421
421
  function toAddress(value) {
422
422
  if (!_viem.isAddress.call(void 0, value)) {
423
- throw new (0, _chunkDYPABUKCcjs.DimesError)("invalid_address", `Invalid EVM address: ${value}`);
423
+ throw new (0, _chunk72LTVPD2cjs.DimesError)("invalid_address", `Invalid EVM address: ${value}`);
424
424
  }
425
425
  return _viem.getAddress.call(void 0, value);
426
426
  }
@@ -705,7 +705,7 @@ async function verifyOfferSignature(client, offer, userAddress) {
705
705
  const recoveredSigner = await recoverCreatePositionSigner(offer, userAddress);
706
706
  const expectedSigner = _viem.getAddress.call(void 0, info.polygonSignerAddress);
707
707
  if (recoveredSigner !== expectedSigner) {
708
- throw new (0, _chunkDYPABUKCcjs.DimesContractError)(
708
+ throw new (0, _chunk72LTVPD2cjs.DimesContractError)(
709
709
  "invalid_signer",
710
710
  `Recovered signer ${recoveredSigner} does not match expected authority ${expectedSigner}`
711
711
  );
@@ -796,12 +796,12 @@ function firstLine(s) {
796
796
  }
797
797
  function formatContractError(err) {
798
798
  if (!err) {
799
- return new (0, _chunkDYPABUKCcjs.DimesContractError)("unknown", "Transaction failed.");
799
+ return new (0, _chunk72LTVPD2cjs.DimesContractError)("unknown", "Transaction failed.");
800
800
  }
801
801
  if (err instanceof _viem.BaseError) {
802
802
  const rejected = err.walk((e) => e instanceof _viem.UserRejectedRequestError);
803
803
  if (rejected) {
804
- return new (0, _chunkDYPABUKCcjs.DimesContractError)("UserRejected", "Transaction rejected in wallet.");
804
+ return new (0, _chunk72LTVPD2cjs.DimesContractError)("UserRejected", "Transaction rejected in wallet.");
805
805
  }
806
806
  const reverted = err.walk(
807
807
  (e) => e instanceof _viem.ContractFunctionRevertedError
@@ -812,12 +812,12 @@ function formatContractError(err) {
812
812
  if (errorName) {
813
813
  const fmt = friendlyByErrorName[errorName];
814
814
  const message = fmt ? fmt(args) : humanizeName(errorName);
815
- return new (0, _chunkDYPABUKCcjs.DimesContractError)(errorName, message);
815
+ return new (0, _chunk72LTVPD2cjs.DimesContractError)(errorName, message);
816
816
  }
817
817
  const raw = reverted.raw;
818
818
  const selector = raw && raw.length >= HEX_SELECTOR_LENGTH ? raw.slice(0, HEX_SELECTOR_LENGTH) : void 0;
819
819
  const selectorMessage = selector ? friendlyBySelector[selector] : void 0;
820
- return new (0, _chunkDYPABUKCcjs.DimesContractError)(
820
+ return new (0, _chunk72LTVPD2cjs.DimesContractError)(
821
821
  _nullishCoalesce(selector, () => ( "unknown_revert")),
822
822
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
823
823
  _nullishCoalesce(_nullishCoalesce(selectorMessage, () => ( reverted.shortMessage)), () => ( "Contract reverted."))
@@ -825,17 +825,17 @@ function formatContractError(err) {
825
825
  }
826
826
  const exec = err.walk((e) => e instanceof _viem.ContractFunctionExecutionError);
827
827
  if (_optionalChain([exec, 'optionalAccess', _5 => _5.shortMessage])) {
828
- return new (0, _chunkDYPABUKCcjs.DimesContractError)("execution_error", firstLine(exec.shortMessage));
828
+ return new (0, _chunk72LTVPD2cjs.DimesContractError)("execution_error", firstLine(exec.shortMessage));
829
829
  }
830
830
  if (err.shortMessage) {
831
- return new (0, _chunkDYPABUKCcjs.DimesContractError)("base_error", firstLine(err.shortMessage));
831
+ return new (0, _chunk72LTVPD2cjs.DimesContractError)("base_error", firstLine(err.shortMessage));
832
832
  }
833
- return new (0, _chunkDYPABUKCcjs.DimesContractError)("base_error", firstLine(err.message));
833
+ return new (0, _chunk72LTVPD2cjs.DimesContractError)("base_error", firstLine(err.message));
834
834
  }
835
835
  if (err instanceof Error) {
836
- return new (0, _chunkDYPABUKCcjs.DimesContractError)("error", firstLine(err.message));
836
+ return new (0, _chunk72LTVPD2cjs.DimesContractError)("error", firstLine(err.message));
837
837
  }
838
- return new (0, _chunkDYPABUKCcjs.DimesContractError)("unknown", "Transaction failed.");
838
+ return new (0, _chunk72LTVPD2cjs.DimesContractError)("unknown", "Transaction failed.");
839
839
  }
840
840
 
841
841
 
@@ -1,8 +1,8 @@
1
1
  import { Abi, Address, Hex } from 'viem';
2
2
  export { Address, Hex } from 'viem';
3
- import { O as Offer } from '../aliases-Dtl19fcM.cjs';
4
- import { D as DimesClient } from '../dimes-client-Bd7DE-tr.cjs';
5
- import { a as DimesContractError } from '../dimes-error-DNcs8hsc.cjs';
3
+ import { O as Offer } from '../aliases-ByZ2DcA5.cjs';
4
+ import { D as DimesClient } from '../dimes-client-B-thu7VQ.cjs';
5
+ import { a as DimesContractError } from '../dimes-error-BY5qVGZC.cjs';
6
6
 
7
7
  declare const vaultAbi: Abi;
8
8
  declare const erc20Abi: readonly [{
@@ -1,8 +1,8 @@
1
1
  import { Abi, Address, Hex } from 'viem';
2
2
  export { Address, Hex } from 'viem';
3
- import { O as Offer } from '../aliases-Dtl19fcM.js';
4
- import { D as DimesClient } from '../dimes-client-DsRQSCTw.js';
5
- import { a as DimesContractError } from '../dimes-error-B46ZbXNX.js';
3
+ import { O as Offer } from '../aliases-ByZ2DcA5.js';
4
+ import { D as DimesClient } from '../dimes-client-CerC9mTr.js';
5
+ import { a as DimesContractError } from '../dimes-error-CrvPuFzB.js';
6
6
 
7
7
  declare const vaultAbi: Abi;
8
8
  declare const erc20Abi: readonly [{
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  DimesContractError,
3
3
  DimesError
4
- } from "../chunk-BVILILIV.mjs";
4
+ } from "../chunk-PZCBUVPD.mjs";
5
5
 
6
6
  // src/contract/vault-abi.json
7
7
  var vault_abi_default = {
@@ -1,4 +1,4 @@
1
- import { M as Market, C as CreateOfferParams, O as Offer, P as Position, A as PositionTransactions, c as ContractInfo, e as CustomerLimit } from './aliases-Dtl19fcM.js';
1
+ import { M as Market, C as CreateOfferParams, O as Offer, P as Position, H as PositionTransactions, d as ContractInfo, f as CustomerLimit, F as FeeRates, j as FeeReportParams, i as FeeReport } from './aliases-ByZ2DcA5.cjs';
2
2
 
3
3
  declare const marketMovedCodes: Set<string>;
4
4
  type QuoteHint = {
@@ -18,6 +18,9 @@ type QuoteHint = {
18
18
  kind: "raise-slippage";
19
19
  currentSlippageBps: number;
20
20
  maxSlippageBps: number;
21
+ } | {
22
+ kind: "raise-min-fill";
23
+ minFillBps: number;
21
24
  } | {
22
25
  kind: "market-full";
23
26
  } | {
@@ -29,7 +32,7 @@ type Params = Record<string, unknown> | null | undefined;
29
32
  declare function quoteErrorHint(code: string | null, params: Params, context: {
30
33
  leverageBps: number;
31
34
  }): QuoteHint;
32
- type CorrectedField = "collateral" | "leverage" | "slippage";
35
+ type CorrectedField = "collateral" | "leverage" | "slippage" | "minFill";
33
36
  type HintAdjustment = {
34
37
  field: "collateral";
35
38
  fromValue: number;
@@ -48,11 +51,18 @@ type HintAdjustment = {
48
51
  toValue: number;
49
52
  toLabel: string;
50
53
  reason: "raise-slippage";
54
+ } | {
55
+ field: "minFill";
56
+ fromValue: number;
57
+ toValue: number;
58
+ toLabel: string;
59
+ reason: "raise-min-fill";
51
60
  } | null;
52
61
  declare function hintAdjustment(hint: QuoteHint, current: {
53
62
  collateralUsd: number;
54
63
  leverageBps: number;
55
64
  slippageBps: number;
65
+ minFillBps?: number;
56
66
  }): HintAdjustment;
57
67
 
58
68
  interface Paginated<T> {
@@ -120,6 +130,9 @@ interface GetPositionsParams {
120
130
  limit?: number;
121
131
  status?: "open" | "closed";
122
132
  }
133
+ interface GetFeeRatesParams {
134
+ ticker?: string;
135
+ }
123
136
  declare class DimesClient {
124
137
  private readonly http;
125
138
  constructor(options: DimesClientOptions);
@@ -133,6 +146,8 @@ declare class DimesClient {
133
146
  cancelPosition(positionId: string): Promise<void>;
134
147
  getContractInfo(): Promise<ContractInfo>;
135
148
  getLimits(): Promise<CustomerLimit>;
149
+ getFeeRates(params?: GetFeeRatesParams): Promise<FeeRates>;
150
+ getFeeReport(params: FeeReportParams): Promise<FeeReport>;
136
151
  }
137
152
 
138
- export { ApiKeyAuth as A, type CorrectedField as C, DimesClient as D, type GetMarketsParams as G, type HintAdjustment as H, JwtAuth as J, type MarketSort as M, type Paginated as P, type QuoteHint as Q, type ApiKeyAuthOptions as a, type AuthProvider as b, type DimesClientOptions as c, type GetPositionsParams as d, type JwtAuthOptions as e, hintAdjustment as h, marketMovedCodes as m, quoteErrorHint as q };
153
+ export { ApiKeyAuth as A, type CorrectedField as C, DimesClient as D, type GetFeeRatesParams as G, type HintAdjustment as H, JwtAuth as J, type MarketSort as M, type Paginated as P, type QuoteHint as Q, type ApiKeyAuthOptions as a, type AuthProvider as b, type DimesClientOptions as c, type GetMarketsParams as d, type GetPositionsParams as e, type JwtAuthOptions as f, hintAdjustment as h, marketMovedCodes as m, quoteErrorHint as q };
@@ -1,4 +1,4 @@
1
- import { M as Market, C as CreateOfferParams, O as Offer, P as Position, A as PositionTransactions, c as ContractInfo, e as CustomerLimit } from './aliases-Dtl19fcM.cjs';
1
+ import { M as Market, C as CreateOfferParams, O as Offer, P as Position, H as PositionTransactions, d as ContractInfo, f as CustomerLimit, F as FeeRates, j as FeeReportParams, i as FeeReport } from './aliases-ByZ2DcA5.js';
2
2
 
3
3
  declare const marketMovedCodes: Set<string>;
4
4
  type QuoteHint = {
@@ -18,6 +18,9 @@ type QuoteHint = {
18
18
  kind: "raise-slippage";
19
19
  currentSlippageBps: number;
20
20
  maxSlippageBps: number;
21
+ } | {
22
+ kind: "raise-min-fill";
23
+ minFillBps: number;
21
24
  } | {
22
25
  kind: "market-full";
23
26
  } | {
@@ -29,7 +32,7 @@ type Params = Record<string, unknown> | null | undefined;
29
32
  declare function quoteErrorHint(code: string | null, params: Params, context: {
30
33
  leverageBps: number;
31
34
  }): QuoteHint;
32
- type CorrectedField = "collateral" | "leverage" | "slippage";
35
+ type CorrectedField = "collateral" | "leverage" | "slippage" | "minFill";
33
36
  type HintAdjustment = {
34
37
  field: "collateral";
35
38
  fromValue: number;
@@ -48,11 +51,18 @@ type HintAdjustment = {
48
51
  toValue: number;
49
52
  toLabel: string;
50
53
  reason: "raise-slippage";
54
+ } | {
55
+ field: "minFill";
56
+ fromValue: number;
57
+ toValue: number;
58
+ toLabel: string;
59
+ reason: "raise-min-fill";
51
60
  } | null;
52
61
  declare function hintAdjustment(hint: QuoteHint, current: {
53
62
  collateralUsd: number;
54
63
  leverageBps: number;
55
64
  slippageBps: number;
65
+ minFillBps?: number;
56
66
  }): HintAdjustment;
57
67
 
58
68
  interface Paginated<T> {
@@ -120,6 +130,9 @@ interface GetPositionsParams {
120
130
  limit?: number;
121
131
  status?: "open" | "closed";
122
132
  }
133
+ interface GetFeeRatesParams {
134
+ ticker?: string;
135
+ }
123
136
  declare class DimesClient {
124
137
  private readonly http;
125
138
  constructor(options: DimesClientOptions);
@@ -133,6 +146,8 @@ declare class DimesClient {
133
146
  cancelPosition(positionId: string): Promise<void>;
134
147
  getContractInfo(): Promise<ContractInfo>;
135
148
  getLimits(): Promise<CustomerLimit>;
149
+ getFeeRates(params?: GetFeeRatesParams): Promise<FeeRates>;
150
+ getFeeReport(params: FeeReportParams): Promise<FeeReport>;
136
151
  }
137
152
 
138
- export { ApiKeyAuth as A, type CorrectedField as C, DimesClient as D, type GetMarketsParams as G, type HintAdjustment as H, JwtAuth as J, type MarketSort as M, type Paginated as P, type QuoteHint as Q, type ApiKeyAuthOptions as a, type AuthProvider as b, type DimesClientOptions as c, type GetPositionsParams as d, type JwtAuthOptions as e, hintAdjustment as h, marketMovedCodes as m, quoteErrorHint as q };
153
+ export { ApiKeyAuth as A, type CorrectedField as C, DimesClient as D, type GetFeeRatesParams as G, type HintAdjustment as H, JwtAuth as J, type MarketSort as M, type Paginated as P, type QuoteHint as Q, type ApiKeyAuthOptions as a, type AuthProvider as b, type DimesClientOptions as c, type GetMarketsParams as d, type GetPositionsParams as e, type JwtAuthOptions as f, hintAdjustment as h, marketMovedCodes as m, quoteErrorHint as q };
@@ -1,4 +1,4 @@
1
- import { Q as QuoteHint } from './dimes-client-Bd7DE-tr.cjs';
1
+ import { Q as QuoteHint } from './dimes-client-B-thu7VQ.cjs';
2
2
 
3
3
  declare class DimesError extends Error {
4
4
  readonly code: string;
@@ -1,4 +1,4 @@
1
- import { Q as QuoteHint } from './dimes-client-DsRQSCTw.js';
1
+ import { Q as QuoteHint } from './dimes-client-CerC9mTr.js';
2
2
 
3
3
  declare class DimesError extends Error {
4
4
  readonly code: string;
package/dist/index.cjs CHANGED
@@ -4,14 +4,14 @@
4
4
 
5
5
 
6
6
 
7
- var _chunkCOSLZ5TMcjs = require('./chunk-COSLZ5TM.cjs');
7
+ var _chunkY5WQ3UWFcjs = require('./chunk-Y5WQ3UWF.cjs');
8
8
 
9
9
 
10
10
 
11
11
 
12
12
 
13
13
 
14
- var _chunkDYPABUKCcjs = require('./chunk-DYPABUKC.cjs');
14
+ var _chunk72LTVPD2cjs = require('./chunk-72LTVPD2.cjs');
15
15
 
16
16
 
17
17
  var _chunkUHQZSMUDcjs = require('./chunk-UHQZSMUD.cjs');
@@ -59,7 +59,7 @@ async function throwFromResponse(response) {
59
59
  const message = _nullishCoalesce(_optionalChain([parsed, 'optionalAccess', _5 => _5.error, 'optionalAccess', _6 => _6.message]), () => ( `API error ${response.status}`));
60
60
  const rawParams = _optionalChain([parsed, 'optionalAccess', _7 => _7.error, 'optionalAccess', _8 => _8.params]);
61
61
  const params = rawParams ? _humps.camelizeKeys.call(void 0, rawParams) : null;
62
- throw new (0, _chunkDYPABUKCcjs.DimesApiError)({ status: response.status, code, type, message, params });
62
+ throw new (0, _chunk72LTVPD2cjs.DimesApiError)({ status: response.status, code, type, message, params });
63
63
  }
64
64
  var HttpClient = class {
65
65
 
@@ -186,6 +186,16 @@ var DimesClient = class {
186
186
  async getLimits() {
187
187
  return this.http.request("/v1/prediction-markets/limits");
188
188
  }
189
+ async getFeeRates(params) {
190
+ const query = params ? buildQueryFromEntries(Object.entries(params)) : "";
191
+ return this.http.request(`/v1/prediction-markets/fee-rates${query}`);
192
+ }
193
+ async getFeeReport(params) {
194
+ return this.http.request("/v1/prediction-markets/fee-reports", {
195
+ method: "POST",
196
+ body: JSON.stringify(_humps.decamelizeKeys.call(void 0, params))
197
+ });
198
+ }
189
199
  };
190
200
 
191
201
  // src/client/auth.ts
@@ -233,7 +243,7 @@ var ApiKeyAuth = (_class = class {
233
243
  });
234
244
  if (!response.ok) {
235
245
  const text = await response.text();
236
- throw new (0, _chunkDYPABUKCcjs.DimesError)("auth_token_failed", `Failed to obtain auth token (${response.status}): ${text}`);
246
+ throw new (0, _chunk72LTVPD2cjs.DimesError)("auth_token_failed", `Failed to obtain auth token (${response.status}): ${text}`);
237
247
  }
238
248
  const data = await response.json();
239
249
  this.jwt = data.token;
@@ -273,7 +283,7 @@ var JwtAuth = (_class2 = class {
273
283
  const response = await this.fetchFn(this.tokenUrl);
274
284
  if (!response.ok) {
275
285
  const text = await response.text();
276
- throw new (0, _chunkDYPABUKCcjs.DimesError)(
286
+ throw new (0, _chunk72LTVPD2cjs.DimesError)(
277
287
  "auth_token_failed",
278
288
  `Failed to fetch token from ${this.tokenUrl} (${response.status}): ${text}`
279
289
  );
@@ -421,6 +431,25 @@ function maxViableLeverageBpsForCollateral(market, side, collateralUsd) {
421
431
  }
422
432
 
423
433
  // src/utils/fees.ts
434
+ var BPS_DIVISOR = 1e4;
435
+ function resolveProtocolOriginationFeeBps(tiers, leverageBps) {
436
+ const lastTier = tiers[tiers.length - 1];
437
+ if (!lastTier) {
438
+ return 0;
439
+ }
440
+ for (const tier of tiers) {
441
+ if (leverageBps <= tier.maxLeverageBps) {
442
+ return tier.feeBps;
443
+ }
444
+ }
445
+ return lastTier.feeBps;
446
+ }
447
+ function resolveOriginationFeeBps(tiers, leverageBps, partnerOriginationFeeBps) {
448
+ return resolveProtocolOriginationFeeBps(tiers, leverageBps) + partnerOriginationFeeBps;
449
+ }
450
+ function computeOriginationFeeUsdcUnits(notionalUsdcUnits, combinedOriginationFeeBps) {
451
+ return Math.floor(notionalUsdcUnits * combinedOriginationFeeBps / BPS_DIVISOR);
452
+ }
424
453
  function getEntry(position) {
425
454
  return position.entry;
426
455
  }
@@ -443,6 +472,59 @@ function getOriginationFeeBreakdown(position) {
443
472
  };
444
473
  }
445
474
 
475
+ // src/utils/max-gain.ts
476
+ var BPS_DIVISOR2 = 1e4;
477
+ var USDC_UNITS_PER_USD = 1e6;
478
+ var TOKEN_UNITS_PER_TOKEN = 1e6;
479
+ function computePolymarketTradingFee(input) {
480
+ const { notionalUsdcUnits, priceUsd, feeRateBps } = input;
481
+ const feeExponent = _nullishCoalesce(input.feeExponent, () => ( 1));
482
+ const builderTakerFeeRateBps = _nullishCoalesce(input.builderTakerFeeRateBps, () => ( 0));
483
+ if (priceUsd <= 0) {
484
+ return 0;
485
+ }
486
+ const notionalUsd = notionalUsdcUnits / USDC_UNITS_PER_USD;
487
+ const contracts = notionalUsd / priceUsd;
488
+ const curvature = (priceUsd * (1 - priceUsd)) ** feeExponent;
489
+ const protocolFeeUsdcUnits = feeRateBps / BPS_DIVISOR2 * contracts * curvature * USDC_UNITS_PER_USD;
490
+ const builderFeeUsdcUnits = builderTakerFeeRateBps / BPS_DIVISOR2 * notionalUsdcUnits;
491
+ return Math.ceil(protocolFeeUsdcUnits + builderFeeUsdcUnits);
492
+ }
493
+ function expectedPositionTokenUnits(notionalUsdcUnits, entryPriceUsd, slippageBps = 0) {
494
+ if (entryPriceUsd <= 0) {
495
+ return 0;
496
+ }
497
+ const notionalUsd = notionalUsdcUnits / USDC_UNITS_PER_USD;
498
+ const tokens = notionalUsd / entryPriceUsd;
499
+ const slippageFactor = (BPS_DIVISOR2 - slippageBps) / BPS_DIVISOR2;
500
+ return Math.floor(tokens * slippageFactor * TOKEN_UNITS_PER_TOKEN);
501
+ }
502
+ function estimateLiquidationPrice(entryPriceUsd, leverageBps, liquidationFeeBps) {
503
+ const leverage = leverageBps / BPS_DIVISOR2;
504
+ if (leverage <= 1) {
505
+ return 0;
506
+ }
507
+ const loanPerToken = entryPriceUsd * ((leverage - 1) / leverage);
508
+ return loanPerToken * (1 + liquidationFeeBps / BPS_DIVISOR2);
509
+ }
510
+ function computeMaxGain(input) {
511
+ const fullValueOnWinUsdcUnits = input.positionTokenUnits;
512
+ const grossMaxGainUsdcUnits = fullValueOnWinUsdcUnits - input.notionalUsdcUnits;
513
+ const netMaxGainUsdcUnits = grossMaxGainUsdcUnits - input.expectedOpenTradingFeeUsdcUnits - input.originationFeeUsdcUnits;
514
+ return {
515
+ fullValueOnWinUsdcUnits,
516
+ grossMaxGainUsdcUnits,
517
+ netMaxGainUsdcUnits
518
+ };
519
+ }
520
+
521
+
522
+
523
+
524
+
525
+
526
+
527
+
446
528
 
447
529
 
448
530
 
@@ -469,5 +551,5 @@ function getOriginationFeeBreakdown(position) {
469
551
 
470
552
 
471
553
 
472
- exports.ApiKeyAuth = ApiKeyAuth; exports.DimesApiError = _chunkDYPABUKCcjs.DimesApiError; exports.DimesClient = DimesClient; exports.DimesContractError = _chunkDYPABUKCcjs.DimesContractError; exports.DimesError = _chunkDYPABUKCcjs.DimesError; exports.JwtAuth = JwtAuth; exports.buildQuoteParams = _chunkCOSLZ5TMcjs.buildQuoteParams; exports.defaultSide = defaultSide; exports.executeQuote = _chunkCOSLZ5TMcjs.executeQuote; exports.formatErrorMessage = _chunkDYPABUKCcjs.formatErrorMessage; exports.getOriginationFeeBreakdown = getOriginationFeeBreakdown; exports.getSidedEligibility = getSidedEligibility; exports.hintAdjustment = _chunkCOSLZ5TMcjs.hintAdjustment; exports.isClosedPosition = isClosedPosition; exports.isFullyClosed = isFullyClosed; exports.isFullyOpen = isFullyOpen; exports.isOpenPosition = isOpenPosition; exports.leverageMaxBps = leverageMaxBps; exports.marketMovedCodes = _chunkCOSLZ5TMcjs.marketMovedCodes; exports.maxLeverageBpsAtNotional = maxLeverageBpsAtNotional; exports.maxViableLeverageBpsForCollateral = maxViableLeverageBpsForCollateral; exports.positionEventTypes = _chunkUHQZSMUDcjs.positionEventTypes; exports.quoteErrorHint = _chunkCOSLZ5TMcjs.quoteErrorHint; exports.rejectionReasonShort = rejectionReasonShort; exports.rejectionReasonText = rejectionReasonText; exports.resolveFriendlyMessage = _chunkDYPABUKCcjs.resolveFriendlyMessage;
554
+ exports.ApiKeyAuth = ApiKeyAuth; exports.DimesApiError = _chunk72LTVPD2cjs.DimesApiError; exports.DimesClient = DimesClient; exports.DimesContractError = _chunk72LTVPD2cjs.DimesContractError; exports.DimesError = _chunk72LTVPD2cjs.DimesError; exports.JwtAuth = JwtAuth; exports.buildQuoteParams = _chunkY5WQ3UWFcjs.buildQuoteParams; exports.computeMaxGain = computeMaxGain; exports.computeOriginationFeeUsdcUnits = computeOriginationFeeUsdcUnits; exports.computePolymarketTradingFee = computePolymarketTradingFee; exports.defaultSide = defaultSide; exports.estimateLiquidationPrice = estimateLiquidationPrice; exports.executeQuote = _chunkY5WQ3UWFcjs.executeQuote; exports.expectedPositionTokenUnits = expectedPositionTokenUnits; exports.formatErrorMessage = _chunk72LTVPD2cjs.formatErrorMessage; exports.getOriginationFeeBreakdown = getOriginationFeeBreakdown; exports.getSidedEligibility = getSidedEligibility; exports.hintAdjustment = _chunkY5WQ3UWFcjs.hintAdjustment; exports.isClosedPosition = isClosedPosition; exports.isFullyClosed = isFullyClosed; exports.isFullyOpen = isFullyOpen; exports.isOpenPosition = isOpenPosition; exports.leverageMaxBps = leverageMaxBps; exports.marketMovedCodes = _chunkY5WQ3UWFcjs.marketMovedCodes; exports.maxLeverageBpsAtNotional = maxLeverageBpsAtNotional; exports.maxViableLeverageBpsForCollateral = maxViableLeverageBpsForCollateral; exports.positionEventTypes = _chunkUHQZSMUDcjs.positionEventTypes; exports.quoteErrorHint = _chunkY5WQ3UWFcjs.quoteErrorHint; exports.rejectionReasonShort = rejectionReasonShort; exports.rejectionReasonText = rejectionReasonText; exports.resolveFriendlyMessage = _chunk72LTVPD2cjs.resolveFriendlyMessage; exports.resolveOriginationFeeBps = resolveOriginationFeeBps; exports.resolveProtocolOriginationFeeBps = resolveProtocolOriginationFeeBps;
473
555
  //# sourceMappingURL=index.cjs.map