import { OrderEnqueued } from "../contracts/deepbook_predict_orders/queue_events.mjs"; import { DelayedExecutionPolicy, HeldPosition, OrderKindName, RefundReasonInfo } from "./queue.mjs"; //#region src/predict/decode.d.ts /** The slice of an executed/simulated transaction result the decoders need. */ interface DecodableEvent { /** Full type tag `0xpkg::module::Name` (gRPC `eventType`, legacy `type`). */ eventType?: string; type?: string; packageId?: string; module?: string; /** Struct name, when the transport supplies it separately from a full type tag. */ name?: string; /** Canonical BCS payload; some transports deliver it base64-encoded. */ bcs?: Uint8Array | string; } interface DecodableTransactionResult { events?: readonly DecodableEvent[] | null; } interface MintReceipt { marketId: string; accountId: string; owner: string; /** Persist this: required to redeem/claim the position later. */ orderId: bigint; /** Stable across partial-close replacements; equals orderId at mint. */ positionRootId: bigint; lowerTick: bigint; higherTick: bigint; /** 0..1 range probability quoted at entry (your fill price per $1 payout). */ entryProbability: number; /** Max payout actually minted, in quote units (mintAmount: chain-floored). */ quantity: number; /** Premium paid into LP backing, in quote units. */ premium: number; /** * Fee breakdown. `referral` is the slice of the trader-paid trading fee and * congestion surcharge delivered to the referrer; `inventoryImpact` is the * path-independent inventory-impact charge assessed on the mint. */ fees: { trading: number; subsidy: number; builder: number; penalty: number; referral: number; inventoryImpact: number; }; builderCodeId: string | null; raw: { quantity: bigint; premium: bigint; tradingFee: bigint; feeIncentiveSubsidy: bigint; builderFee: bigint; penaltyFee: bigint; referralFee: bigint; inventoryImpactCharge: bigint; entryProbability: bigint; }; } interface RedeemReceipt { marketId: string; accountId: string; owner: string; orderId: bigint; positionRootId: bigint; quantityClosed: number; remaining: number; /** * A partial close RETIRES the old order id and issues this replacement for * the remaining quantity — update your stored id or it goes silently stale. */ replacementOrderId: bigint | null; /** NET quote credited to the account: gross + inventoryImpactRebate − trading − * builder − penalty — the same expression the chain asserts `min_proceeds` * against, and what `settle_live_redeem_payment` actually deposits. */ proceeds: number; /** Gross close value before fees (the event's redeem_amount). */ gross: number; /** * Fee breakdown. `inventoryImpactRebate` is the path-independent * inventory-impact rebate credited back on the close. */ fees: { trading: number; builder: number; penalty: number; inventoryImpactRebate: number; }; builderCodeId: string | null; raw: { quantityClosed: bigint; remaining: bigint; proceeds: bigint; gross: bigint; tradingFee: bigint; builderFee: bigint; penaltyFee: bigint; inventoryImpactRebate: bigint; }; } interface ClaimReceipt { marketId: string; accountId: string; owner: string; orderId: bigint; positionRootId: bigint; /** Quote units paid out. A settled claim closes the order in full. */ payout: number; raw: { payout: bigint; }; } interface CreateManagerReceipt { accountId: string; wrapperId: string; owner: string; selfOwned: boolean; } interface BalanceChangeReceipt { accountId: string; coinType: string; /** Display value assuming a 6-decimal coin (quote + PLP both are). */ amount: number; newBalance: number; raw: { amount: bigint; newBalance: bigint; }; } interface PlpRequestReceipt { kind: 'supply' | 'withdraw'; vaultId: string; accountId: string; recipient: string; /** Feed straight into cancelSupplyPlp / cancelWithdrawPlp. */ index: bigint; /** Quote units for supply; PLP shares (6-dec) for withdraw. */ amount: number; raw: { amount: bigint; }; } interface PlpCancelReceipt { vaultId: string; accountId: string; recipient: string; index: bigint; isSupply: boolean; /** Refund returned to the account (quote for supply, PLP for withdraw). */ amount: number; raw: { amount: bigint; }; } interface BuilderCodeReceipt { accountId: string; owner: string; /** Null after unsetBuilderCode. */ builderCodeId: string | null; } /** The market's cash figures after the call, as the queue events report them. */ interface QueueCashFigures { marketCash: bigint; requiredCash: bigint; waitingCashNeed: bigint; } /** `OrderEnqueued`: the trader's own receipt for a queued mint or sell. Drives "Placed". */ interface EnqueueReceipt { type: 'enqueued'; marketId: string; /** The record ID: what `read.order`, `quoteSell` and `enqueueSell` take. Persist it. */ recordId: bigint; accountId: string; kind: number; kindName: OrderKindName; side: 'mint' | 'sell' | 'unknown'; request: { lowerTick: bigint; higherTick: bigint; quantity: bigint; maxPremium: bigint; minQuantity: bigint; maxCost: bigint; maxProbability: bigint; minProbability: bigint; minProceeds: bigint; }; /** The position a sell moved into the record. Null for a mint. */ position: HeldPosition | null; timing: { placedAtMs: bigint; earliestPriceMs: bigint; tauMs: bigint; deadlineMs: bigint; cutoffMs: bigint; pythChannel: number; }; /** The Open record a sell took its position from. Null for a mint. */ sourceRecordId: bigint | null; builderCodeId: string | null; referrerAccountId: string | null; /** USDC escrowed for the premium and fees (0 for a sell). */ budget: number; orderFee: number; cash: QueueCashFigures; /** `onchain_timestamp_ms`: the placement transaction's clock. */ timestampMs: bigint; raw: { budget: bigint; orderFee: bigint; cashNeed: bigint; subsidyBound: bigint; }; /** The volatility snapshot the fill prices with, as the generated layout parses it. */ vol: (typeof OrderEnqueued)['$inferType']['vol']; } /** `CohortCommitted`: a price attached to the records `firstRecordId..=lastRecordId`. Drives "Priced". */ interface CohortCommitReceipt { type: 'cohort-committed'; marketId: string; tauMs: bigint; /** The update's envelope: τ, or the backup tick one channel tick later. */ tickMs: bigint; firstRecordId: bigint; /** Inclusive. */ lastRecordId: bigint; /** The committed price of the cohort's first order as a float: `spotRaw / 1e9`. */ price: number; /** The committed price, normalized to 1e9. */ spotRaw: bigint; /** That price's own update time, in µs. */ generationUs: bigint; pythSourceId: number; pythChannel: number; /** Who committed: a keeper, or any third-party filler. */ sender: string; /** `onchain_timestamp_ms`. */ timestampMs: bigint; } /** `QueuedOrderFilled`. Report "Filled" only from this event (or the record). */ interface QueuedFillReceipt { type: 'filled'; marketId: string; recordId: bigint; accountId: string; kind: number; side: 'mint' | 'sell' | 'unknown'; /** Filled quantity (mint) or closed quantity (sell). */ quantity: number; /** Cost paid (mint) or proceeds before the order fee (sell). */ amount: number; fees: { trading: number; builder: number; referral: number; order: number; subsidyUsed: number; inventoryImpact: number; }; tauMs: bigint; tickMs: bigint; /** The record's position now: a mint's new position, a partial sell's remainder, or null. */ position: HeldPosition | null; sender: string; timestampMs: bigint; cash: QueueCashFigures; raw: { quantity: bigint; amount: bigint; tradingFee: bigint; builderFee: bigint; referralFee: bigint; orderFee: bigint; subsidyUsed: bigint; inventoryImpact: bigint; }; } /** * `QueuedOrderRefunded`, from whichever path refunded the order: resolve, a deadline refund, an * admin refund, or the settlement drain (`settle_step`, reason 5). `sender` is always the * transaction's sender. */ interface QueuedRefundReceipt { type: 'refunded'; marketId: string; recordId: bigint; accountId: string; kind: number; side: 'mint' | 'sell' | 'unknown'; reason: RefundReasonInfo; escrowReturned: number; orderFeeReturned: number; subsidyReturned: number; /** True when a sell's record went back to Open holding its position. */ positionReturned: boolean; sender: string; timestampMs: bigint; cash: QueueCashFigures; raw: { escrowReturned: bigint; orderFeeReturned: bigint; subsidyReturned: bigint; }; } /** * `OpenRecordSettled` (paid, 0 for a loser) or `OpenRecordPayoutSkipped` (stays Open, for a later * `pay_open`), from `settle_step`'s payout walk or `pay_open`. */ interface OpenRecordPayoutReceipt { type: 'open-record-settled' | 'open-record-payout-skipped'; marketId: string; recordId: bigint; accountId: string; orderId: bigint; payout: number; /** True for `OpenRecordPayoutSkipped`: the market couldn't pay it yet. */ skipped: boolean; timestampMs: bigint; raw: { payout: bigint; }; } /** `MarketPayoutsCompleted`: the settlement payout walk is done. */ interface MarketPayoutsCompletedReceipt { type: 'market-payouts-completed'; marketId: string; timestampMs: bigint; } /** * `RecordFundsParked`: a record kept USDC it couldn't send to its receive address (on USDC's deny * list, or USDC paused). `RecordFundsClaimed`: `claim_parked` sent a record's parked funds. */ interface RecordFundsReceipt { type: 'record-funds-parked' | 'record-funds-claimed'; marketId: string; recordId: bigint; accountId: string; receiveAddress: string; /** Parked: this call's parked change or refund. Claimed: everything the record had parked. */ amount: number; timestampMs: bigint; raw: { amount: bigint; }; } /** Queue housekeeping events, for ops and alerts. */ type QueueOpsReceipt = { type: 'queued-orders-cleaned'; marketId: string; recordIds: bigint[]; timestampMs: bigint; }; /** Delayed-execution admin events, for the multisig scripts and monitors. */ type PolicyUpdateReceipt = { /** * The companion desk's `DelayedExecutionPolicyUpdated`, from every policy setter with the * full post-state. The desk's `init` at publish emits none: the launch policy is only the * desk's state. */ type: 'policy-updated'; deskId: string; policy: DelayedExecutionPolicy; timestampMs: bigint; } | { type: 'flush-operator-updated'; operator: string; added: boolean; timestampMs: bigint; } | { /** Predict's `OrderFlowUpdated`: an order-flow witness allowlisted or removed. */type: 'order-flow-updated'; /** The witness type, as Move's `type_name` renders it (no `0x` prefix). */ orderFlow: string; enabled: boolean; timestampMs: bigint; }; /** Every delayed-execution order event, tagged, in chain order. Feed it to `queue.reduceOrderEvents`. */ type QueueEvent = EnqueueReceipt | CohortCommitReceipt | QueuedFillReceipt | QueuedRefundReceipt | OpenRecordPayoutReceipt | MarketPayoutsCompletedReceipt | RecordFundsReceipt | QueueOpsReceipt; /** * `vault_events::ExpiryPnlRealized`: the change in the pool's gross realized result on one expiry * since that expiry's previous emission, emitted with every `ExpiryPnl`. An expiry's first * emission (its first settled sweep) carries the lifetime result, which can be a loss. A later * one carries the extra cash a later sweep returned, always a profit. Gross: before the * protocol/LP split, and including the sponsor fee subsidies mints moved into expiry cash. */ interface ExpiryPnlRealizedReceipt { vaultId: string; marketId: string; propbookUnderlyingId: number; expiryMs: bigint; /** The settlement price, 1e9-scaled. */ settlementPriceRaw: bigint; /** False only for a loss, which only an expiry's first emission reports. */ inProfit: boolean; /** The change's magnitude, in USDC. */ amount: number; /** The change with its sign: `+amount` for a profit, `−amount` for a loss. */ signedAmountRaw: bigint; raw: { amount: bigint; }; } /** * The pool's gross realized P&L in raw USDC: the signed sum of `ExpiryPnlRealized` changes. Over * every emission of every expiry it equals the sum of each expiry's latest `ExpiryPnl`, with no * per-expiry dedup. Subtract the `OrderMinted.fee_incentive_subsidy` totals to isolate the * trading result. */ declare function realizedPnlRaw(receipts: readonly Pick[]): bigint; //#endregion export { BalanceChangeReceipt, BuilderCodeReceipt, ClaimReceipt, CohortCommitReceipt, CreateManagerReceipt, DecodableEvent, DecodableTransactionResult, EnqueueReceipt, ExpiryPnlRealizedReceipt, MarketPayoutsCompletedReceipt, MintReceipt, OpenRecordPayoutReceipt, PlpCancelReceipt, PlpRequestReceipt, PolicyUpdateReceipt, QueueCashFigures, QueueEvent, QueueOpsReceipt, QueuedFillReceipt, QueuedRefundReceipt, RecordFundsReceipt, RedeemReceipt, realizedPnlRaw }; //# sourceMappingURL=decode.d.mts.map