import { DelayedExecutionPolicy as DelayedExecutionPolicy$1 } from "../contracts/deepbook_predict_orders/delayed_execution_config.mjs"; import { OrderView as OrderView$1 } from "../contracts/deepbook_predict_orders/order_queue.mjs"; import { QueueEvent } from "./decode.mjs"; //#region src/predict/queue.d.ts declare namespace queue_d_exports { export { DEADLINE_EXPIRY_MARGIN_MS, DELAYED_EXECUTION_VERSION, DelayedExecutionPolicy, HeldPosition, MaxMintInputs, MaxMintNow, MintBudgetInputs, MintCashNeedInputs, MintLimitsInputs, ORDER_FLOW_PACKAGE_VERSION, ORDER_KIND, ORDER_STATUS, OrderEventState, OrderKindName, OrderStatusName, OrderView, PREDICT_PACKAGE_VERSION, PYTH_CHANNEL, ParkedFunds, PricePerContract, QueueHeads, QueuedOrder, REFUND_REASON, REFUND_REASONS, REFUND_REQUEST_GRACE_MS, RefundReasonInfo, SETTLE_PHASE, SlippageBandInputs, TimingPreview, TimingPreviewInputs, budgetMintLimits, cashNeedBudget, cashNeedExactQuantity, cashNeedSell, channelTickMs, exactMintLimits, feeCovered, isMintKind, isSellKind, maxMintNow, mintBudget, mintCashNeed, orderCutoffMs, orderKindName, orderStatusName, orderView, policyFromBcs, previewTiming, reduceOrderEvents, refundReason, sellCashCheck, sellLimits, slippageBand }; } /** * Predict's `constants::current_version` from the upgrade that added delayed execution. Enqueue * works once `ProtocolConfig.version_watermark` reaches it (Predict's admission aborts * `ECutoverNotReached` until then). The retired immediate trades (`mint_exact_*`, `redeem_live`) * always abort in that package, and the older packages they still run in are retired by the same * bump. The same on both networks: it is the code's version constant, not the on-chain package * version (Mainnet v4, Testnet v5). */ declare const DELAYED_EXECUTION_VERSION = 4n; /** * Predict's `constants::current_version` of the package these bindings were generated from. Every * version-gated Predict call checks `chk_version`, which aborts `EPackageVersionDisabled` once * `ProtocolConfig.version_watermark` is above it, so a higher watermark retires the Predict code * this SDK calls. Bump it with Predict when regenerating. Like `DELAYED_EXECUTION_VERSION` it is the * code's version constant, which follows the Mainnet package number (5 ships as Mainnet v5 and runs * as Testnet package v8), never the Testnet package number. */ declare const PREDICT_PACKAGE_VERSION = 5n; /** * `desk::current_version` of the order-flow package these bindings were generated from. The desk's * version floor retires older companion code, so a floor above it means the package this SDK calls * aborts `EPackageVersionDisabled`. Bump it with the companion when regenerating. It follows the * Mainnet package number (2 ships as Mainnet v2 and runs as Testnet package v3), never the Testnet * package number. */ declare const ORDER_FLOW_PACKAGE_VERSION = 2n; /** `queue::phase_*`: what `settle_step` returns, the phase the next call runs. */ declare const SETTLE_PHASE: Readonly<{ /** Refunding the waiting orders (reason 5). */readonly DRAIN: 0; /** Paying the Open records, once Predict has settled the market. */ readonly PAY: 1; /** * The payout walk reached the last record and `MarketPayoutsCompleted` was emitted. A record * the market couldn't pay (`OpenRecordPayoutSkipped`) stays Open and unpaid. */ readonly DONE: 2; }>; /** `order_queue::status_*`. Never renumbered on chain; unknown codes still decode. */ declare const ORDER_STATUS: Readonly<{ readonly PENDING: 0; readonly COMMITTED: 1; readonly OPEN: 2; readonly REFUNDED: 3; readonly CLOSED: 4; /** Reserved: nothing sets it at launch. Counts as unfinished. */ readonly REFUND_DUE: 5; }>; /** `order_queue::kind_*`. `REDEEM_LIVE` is reserved and never used by v4. */ declare const ORDER_KIND: Readonly<{ readonly EXACT_QUANTITY: 0; readonly EXACT_AMOUNT: 1; readonly EXACT_COST: 2; readonly REDEEM_LIVE: 3; readonly REDEEM_OPEN: 4; }>; /** `order_queue::reason_*`. `0` in a record's result means filled. */ declare const REFUND_REASON: Readonly<{ readonly LIMITS: 1; readonly ADMISSION: 2; readonly NO_PRICE: 3; readonly MISSING_NODE: 4; readonly DEADLINE: 5; readonly FREEZE: 6; readonly ADMIN: 7; readonly NO_CASH: 8; readonly RECIPIENT_DENIED: 9; }>; /** The Pyth Lazer channels the queue prices on (`delayed_execution_config`). */ declare const PYTH_CHANNEL: Readonly<{ readonly FIXED_RATE_50MS: 2; readonly FIXED_RATE_200MS: 3; }>; /** Predict's `constants::deadline_expiry_margin_ms`: every deadline is at least this long before expiry. */ declare const DEADLINE_EXPIRY_MARGIN_MS = 5000n; /** * How long after an order's deadline the app waits before offering "Refund my order". Keepers * refund overdue orders on their own, so the button only matters when they are all down. */ declare const REFUND_REQUEST_GRACE_MS = 5000n; type OrderStatusName = 'pending' | 'committed' | 'open' | 'refunded' | 'closed' | 'refund-due' | 'unknown'; type OrderKindName = 'exact-quantity' | 'exact-amount' | 'exact-cost' | 'redeem-live' | 'redeem-open' | 'unknown'; /** A status code's name, or `'unknown'` for a code this SDK version predates. */ declare function orderStatusName(code: number): OrderStatusName; /** A kind code's name, or `'unknown'` for a code this SDK version predates. */ declare function orderKindName(code: number): OrderKindName; /** Whether a kind code is a queued mint (exact quantity, exact amount or exact cost). */ declare function isMintKind(kind: number): boolean; /** Whether a kind code is a queued sell. */ declare function isSellKind(kind: number): boolean; /** What a refund reason means for the trader. */ interface RefundReasonInfo { code: number; key: 'limits' | 'admission' | 'no-price' | 'missing-node' | 'deadline' | 'freeze' | 'admin' | 'no-cash' | 'recipient-denied' | 'unknown'; /** Display text for the refund. */ text: string; /** Whether the order fee was kept (reasons 1 and 2). `null` for an unknown code. */ feeKept: boolean | null; /** False for codes v4 reserves but never sets (3 and 6), and for unknown codes. */ live: boolean; } /** Every reason code v4 defines, with its text and fee treatment. */ declare const REFUND_REASONS: Readonly>; /** A reason code's meaning. Unknown codes map to `key: 'unknown'` rather than throwing. */ declare function refundReason(code: number): RefundReasonInfo; /** * `delayed_execution_config::DelayedExecutionPolicy` with camelCase keys, as the companion's * `OrderDesk` holds it (`desk::policy`). Times in ms, USDC raw. */ interface DelayedExecutionPolicy { delayMs: bigint; stallTimeoutMs: bigint; stuckThresholdMs: bigint; gapWaitMs: bigint; pythPriceBufferMs: bigint; /** {@link PYTH_CHANNEL}: `2` is 50 ms, `3` is 200 ms. */ pythChannel: number; sviMaxAgeMs: bigint; mintCapacity: bigint; sellCapacity: bigint; perAccountCap: bigint; /** Flat USDC fee charged at enqueue, raw. */ orderFee: bigint; minSellQuantity: bigint; settleRefundBatch: bigint; settlePayoutBatch: bigint; } /** Map the generated policy layout to {@link DelayedExecutionPolicy}. */ declare function policyFromBcs(p: (typeof DelayedExecutionPolicy$1)['$inferType']): DelayedExecutionPolicy; /** `delayed_execution_config::channel_tick_ms`: 50 ms for channel 2, 200 ms for channel 3. */ declare function channelTickMs(channel: number): bigint; /** Exact-quantity mint cash need: `⌈quantity · (1 − p_min)⌉ + 1`. */ declare function cashNeedExactQuantity(quantity: bigint, minEntryProbability: bigint): bigint; /** * Budget mint cash need: `⌈(budget + 1) · (1 / p_min − 1)⌉ + 1`, rounded as Move rounds it (one * `mul_div_up` of `(budget + 1) · (1e9 − p_min) / p_min`). Exact-amount mints pass * `min(max_premium, budget)`. `p_min = 0` throws, as the Move division aborts. */ declare function cashNeedBudget(budget: bigint, minEntryProbability: bigint): bigint; /** Sell cash need: `⌈close_quantity · (1 − λ)⌉ + 1`. */ declare function cashNeedSell(closeQuantity: bigint, backingBufferLambda: bigint): bigint; /** * Whether the account can pay the order fee: a mint needs `available > fee` (it escrows a budget * on top), a sell needs `available ≥ fee` (it escrows only the fee). `available` is * `account::balance`, unsettled accumulator funds included. */ declare function feeCovered(side: 'mint' | 'sell', availableRaw: bigint, orderFeeRaw: bigint): boolean; /** Inputs for {@link mintBudget}. */ interface MintBudgetInputs { /** {@link ORDER_KIND}: a mint kind. */ kind: number; maxCostRaw: bigint; availableRaw: bigint; orderFeeRaw: bigint; /** Required for exact quantity: a fill never costs more than its quantity. */ quantityRaw?: bigint; } /** * The budget a queued mint escrows: `min(max_cost, available − fee)`, and for exact quantity also * at most the quantity. `null` when the balance doesn't cover the fee. Enqueue debits the budget * plus the order fee, and the unspent budget comes back at the fill. */ declare function mintBudget(inputs: MintBudgetInputs): bigint | null; /** Inputs for {@link mintCashNeed}. */ interface MintCashNeedInputs { kind: number; /** The escrowed budget, from {@link mintBudget}. */ budgetRaw: bigint; minEntryProbability: bigint; /** Exact quantity: the quantity ordered. */ quantityRaw?: bigint; /** Exact amount: the premium cap. */ maxPremiumRaw?: bigint; } /** A queued mint's cash need, picking the formula the contract picks for its kind. */ declare function mintCashNeed(inputs: MintCashNeedInputs): bigint; /** * A sell's cash need against the market's spare cash. Sells are never refused for market cash at * placement: the keeper funds the market before τ, and a sell the market still can't cover at the * fill is refunded in full (reason 8). `short` flags that risk, and the sell builder can add * `rebalance_expiry_cash` after the enqueue to fund the market at once. */ declare function sellCashCheck(closeQuantityRaw: bigint, spareCashRaw: bigint, backingBufferLambda: bigint): { needRaw: bigint; short: boolean; }; /** Inputs for {@link maxMintNow}. */ interface MaxMintInputs { /** `'exact-quantity'` sizes a quantity; `'budget'` sizes an exact-cost or exact-amount spend. */ shape: 'exact-quantity' | 'budget'; /** Market cash above required cash (`MarketQueueState.spareCash`). */ spareCashRaw: bigint; /** The minimum entry probability from `expiry_market::order_flow_state`, 1e9-scaled. */ minEntryProbability: bigint; /** `account::balance`. Bounds a budget spend at `available − fee`. */ availableRaw?: bigint; orderFeeRaw?: bigint; /** The deployment's `position_lot_size`. Defaults to `10_000n`. */ lotSize?: bigint; /** Margin left below spare cash, in basis points. Default 100 (1%). */ headroomBps?: bigint; /** When the reads were taken, echoed back as `asOfMs`. */ asOfMs?: bigint; } /** The largest mint a market takes right now, and what binds it. A snapshot: see {@link maxMintNow}. */ interface MaxMintNow { /** * The cash-limited maximum: a quantity for `'exact-quantity'`, a spend for `'budget'`. `null` * when cash doesn't bind (`p_min ≥ 1`). */ cashLimitRaw: bigint | null; /** `available − fee` for `'budget'`, when a balance was given. `null` otherwise. */ balanceLimitRaw: bigint | null; /** The smaller of the two limits, or `null` when neither binds. */ maxRaw: bigint | null; limitedBy: 'cash' | 'balance' | 'none'; asOfMs: bigint | null; } /** * The largest queued mint a market's spare cash admits now ("Max right now"). Predict's admission * refuses a mint whose cash need is above spare cash (`EInsufficientMarketCash`). For exact quantity this * is the largest lot multiple `q` with `cashNeedExactQuantity(q) ≤ S`; for a budget it is the * largest `b` with `cashNeedBudget(b) ≤ S`, where `S` is spare cash less the headroom. * * It is a snapshot: fills lower spare cash, and the keeper's rebalance after each enqueue raises * it. Other waiting orders don't count against a mint. For exact quantity this caps only the * cash side: size the balance side with `cost.mintCostForBudget` at `available − fee`. A budget * mint with `p_min = 0` can't be placed at all (the cash need divides by `p_min`), so it reads 0. */ declare function maxMintNow(inputs: MaxMintInputs): MaxMintNow; /** `(resolve_head, next_id, last_tau_ms, last_committed_tau_ms)` from `queue::queue_heads`. */ interface QueueHeads { resolveHead: bigint; nextId: bigint; lastTauMs: bigint; lastCommittedTauMs: bigint; } /** * `expiry − max(no_trade_window_ms, stall_timeout_ms + 5_000)`, saturating at 0: enqueue requires * the order's τ below it. */ declare function orderCutoffMs(expiryMs: bigint, policy: Pick, noTradeWindowMs: bigint): bigint; /** Inputs for {@link previewTiming}. */ interface TimingPreviewInputs { nowMs: bigint; policy: Pick; heads: QueueHeads; expiryMs: bigint; noTradeWindowMs: bigint; /** * The newest order's channel, when known. A channel change pushes τ past the last τ, so one * cohort never mixes channels. The public reads don't expose it, so it is optional. */ lastChannel?: number; } /** A display preview of the τ, deadline and cutoff an order placed now would get. */ interface TimingPreview { tauMs: bigint; /** `min(τ + stall, expiry)`. The chain also keeps deadlines non-decreasing. */ deadlineMs: bigint; cutoffMs: bigint; tickMs: bigint; /** Whether τ is before the cutoff, so enqueue would accept the timing. */ beforeCutoff: boolean; } /** * Preview `order_queue::plan_timing`: τ is the policy channel's last tick at or before * `now + delay`, never below the last τ, and pushed past the last committed τ. Display only: * the contract uses the consensus timestamp, which can differ from the local clock. */ declare function previewTiming(inputs: TimingPreviewInputs): TimingPreview; /** Inputs for {@link slippageBand}. All times in ms. */ interface SlippageBandInputs { /** The quoted probability, in (0, 1). */ probability: number; timeToExpiryMs: number; /** The policy's delay. */ delayMs: number; /** The channel tick: 50 or 200. */ tickMs: number; /** Time between the quote and the enqueue landing. Default 500. */ signingMs?: number; /** Time between τ and the fill. Default 500. */ resolveMs?: number; /** Standard deviations of movement to allow. Default 2. */ k?: number; } /** * A heuristic band for a queued order's price limits: `Δp ≈ k · φ(Φ⁻¹(p)) · √(h / T)`, the * probability move of a digital under Brownian motion over the horizon `h` (delay + tick + * resolve + signing), scaled by the time `T` left. Use `maxProbability = p + Δp` on exact-quantity * mints and `minProbability = p − Δp` on sells, and size cost caps at the shifted probability. * A sizing aid pending product sign-off, not a contract rule. */ declare function slippageBand(inputs: SlippageBandInputs): { horizonMs: number; deltaProbability: number; maxProbability: number; minProbability: number; }; /** The quote a set of mint limits is sized from: the chain quote at the current price. */ interface MintLimitsInputs { /** The quote's all-in cost after its fee subsidy, order fee excluded. */ quoteCostRaw: bigint; /** The quote's payout quantity. */ quoteQuantityRaw: bigint; /** The quote's entry probability, 1e9-scaled. */ entryProbabilityRaw: bigint; /** The price move to allow per contract, 1e9-scaled: 10¢ is `100_000_000n`. */ slippageRaw: bigint; /** * The quote's fee subsidy (`fee_incentive_subsidy`). Defaults to `0n`. Enqueue admission checks * the order's limits without the subsidy, and the subsidy can run out before the fill, so the * limits add it back: they are sized from the unsubsidized cost. */ feeIncentiveSubsidyRaw?: bigint; /** The deployment's `position_lot_size`. Defaults to `10_000n`. */ lotSize?: bigint; } /** All-in price per $1 of payout, 1e9-scaled and rounded up. */ interface PricePerContract { /** The quote's price, after its fee subsidy. */ nowRaw: bigint; /** The worst price the limits admit: the price without the fee subsidy, plus the slippage. */ worstRaw: bigint; } /** * Limits for a queued all-in budget mint (`enqueueMintCost`): the payout floor at the worst price. * The fill buys what `budgetRaw` buys at τ and refunds the order when that is below * `minQuantityRaw`, so the order fills while the all-in price per $1 of payout stays within * `slippageRaw` of the quote. */ declare function budgetMintLimits(inputs: MintLimitsInputs & { budgetRaw: bigint; }): { minQuantityRaw: bigint; pricePerContract: PricePerContract; }; /** * Limits for a queued exact-quantity mint (`enqueueMint`): the entry-probability cap and the * all-in cost cap at the worst price. The cost cap never exceeds the quantity, since a contract * never costs more than it pays. */ declare function exactMintLimits(inputs: MintLimitsInputs): { maxCostRaw: bigint; maxProbabilityRaw: bigint; pricePerContract: PricePerContract; }; /** * Limits for a queued early sell (`enqueueSell`): the close-probability floor and the proceeds * floor at the worst price. `proceedsRaw` is the quote's proceeds before the order fee, as * `minProceeds` is. */ declare function sellLimits(inputs: { proceedsRaw: bigint; closeQuantityRaw: bigint; probabilityRaw: bigint; slippageRaw: bigint; }): { minProceedsRaw: bigint; minProbabilityRaw: bigint; }; /** * A queue record as `queue::order` returns it: the generated `order_queue::OrderView` layout, a * copy of the record without Predict's receipt and the escrow balance (`funds` is its value). */ type QueuedOrder = (typeof OrderView$1)['$inferType']; /** The position a record holds: a filled mint's, a sell's, or a partial sell's remainder. */ interface HeldPosition { orderId: bigint; rootId: bigint; openedAtMs: bigint; /** * The position's payout quantity, decoded from `orderId` at the Move lot size: a filled * mint's quantity, or what a partial sell left Open. */ quantityRaw: bigint; } interface OrderViewBase { status: number; kind: number; kindName: OrderKindName; side: 'mint' | 'sell' | 'unknown'; } /** * What the app shows for one queued order. `placed` → `priced` → one of `filled` / `refunded`. * Report `filled` only from the record or the fill event, never from a resolve simulation. */ type OrderView = OrderViewBase & ({ state: 'placed'; tauMs: bigint; deadlineMs: bigint; /** τ has passed and the price hasn't been committed yet. */ awaitingPrice: boolean; /** Keepers refund an unfinished order at its deadline. */ autoRefundByMs: bigint; /** Offer "Refund my order": unfinished and {@link REFUND_REQUEST_GRACE_MS} past the deadline. */ canRequestRefund: boolean; } | { state: 'priced'; tauMs: bigint; /** The committed update's tick: τ, or a backup tick. */ tickMs: bigint; /** The committed Pyth price, 1e9-scaled. */ priceRaw: bigint; deadlineMs: bigint; msToDeadline: bigint; autoRefundByMs: bigint; canRequestRefund: boolean; } | { state: 'refunding'; reason: RefundReasonInfo; deadlineMs: bigint; canRequestRefund: boolean; } | { state: 'filled'; /** * Filled quantity (mint) or closed quantity (sell). A partial sell's remainder is * `position.quantityRaw`. */ quantityRaw: bigint; /** Cost paid (mint) or proceeds before the order fee (sell). */ amountRaw: bigint; finishedAtMs: bigint; /** The Open record's position: a filled mint, or a partial sell's remainder. */ position: HeldPosition | null; /** Whether `enqueue_redeem_open` can sell this record now. */ sellable: boolean; /** See {@link ParkedFunds}. */ parkedRaw: bigint; } | { state: 'refunded'; reason: RefundReasonInfo; finishedAtMs: bigint; /** A refunded sell keeps its position as an Open record, sellable again. */ positionBackAsOpenRecord: boolean; position: HeldPosition | null; sellable: boolean; /** See {@link ParkedFunds}. */ parkedRaw: bigint; } | { /** A filled mint's record whose position was later sold or settled. */state: 'closed'; quantityRaw: bigint; amountRaw: bigint; finishedAtMs: bigint; /** See {@link ParkedFunds}. */ parkedRaw: bigint; } | { state: 'unknown'; }); /** * `parkedRaw` on a finished record: USDC the record kept because its receive address couldn't take * it (on USDC's deny list, or USDC paused) when its change or refund was sent. It is the * record's `funds`, which holds only parked USDC once the order finishes. Anyone can send it with * `claim_parked` once the address is clear. `0n` when nothing is parked. */ type ParkedFunds = bigint; /** * Map a queue record to its display state. `nowMs` drives the refund flags. A record is sellable * while it is Open, holds a position, and `nowMs` is before the cutoff (`opts.cutoffMs`, or the * record's own placement cutoff when omitted). Unknown status or kind codes map to `unknown`. * `opts.lotSize` is the config's position lot (default 10,000, Predict's), which decodes a held * position's quantity. */ declare function orderView(record: QueuedOrder, nowMs: bigint, opts?: { cutoffMs?: bigint; lotSize?: bigint; }): OrderView; /** One record's state rebuilt from events, for the app's event path (indexer or own effects). */ interface OrderEventState { marketId: string; recordId: bigint; /** * `closed`: the record's position moved into a later sell's record (`enqueue_redeem_open` closes * the source record), so this record holds nothing any more. */ state: 'placed' | 'priced' | 'filled' | 'refunded' | 'settled' | 'closed'; kind: number | null; tauMs: bigint | null; deadlineMs: bigint | null; /** Set once priced: the committed Pyth price as a float (`spot / 1e9`) and its tick. */ price: number | null; tickMs: bigint | null; /** * Set on a refund. The settlement drain (`settle_step`) refunds the orders still waiting at * expiry with reason 5 (deadline), like a keeper's deadline refund. */ reason: RefundReasonInfo | null; /** * The position the record holds now, or null. A sell's record takes its source's position at * enqueue and keeps it through a refund, a fill leaves a mint's new position or a partial * sell's remainder, and a later sell, a full close or settlement clears it. */ position: HeldPosition | null; /** For a sell: the record its position came from. */ sourceRecordId: bigint | null; /** Set when `settle_step` or `pay_open` paid the record (0 for a loser). */ payoutRaw: bigint | null; /** True after `OpenRecordPayoutSkipped`: the record stays Open, unpaid for now. */ payoutSkipped: boolean; /** * USDC the record holds parked (`RecordFundsParked`, summed) until `RecordFundsClaimed`. See * {@link ParkedFunds}. */ parkedRaw: bigint; } /** * Fold decoded queue events (in chain order) into per-record states, keyed `marketId:recordId`. * The app shows Placed from the enqueue's own effects, Priced at the cohort commit, and switches to * Filled or Refunded on `QueuedOrderFilled` / `QueuedOrderRefunded`. Events for records that never * appeared enqueued still create an entry, so a partial event window works. */ declare function reduceOrderEvents(events: readonly QueueEvent[], into?: Map): Map; //#endregion export { DelayedExecutionPolicy, HeldPosition, MaxMintNow, OrderKindName, OrderView, QueueHeads, QueuedOrder, RefundReasonInfo, TimingPreview, queue_d_exports, slippageBand }; //# sourceMappingURL=queue.d.mts.map