{"version":3,"file":"decode.mjs","names":["orderEvents.OrderMinted","orderEvents.LiveOrderRedeemed","orderEvents.SettledOrderRedeemed","accountEvents.AccountCreated","accountEvents.Deposited","accountEvents.Withdrawn","vaultEvents.SupplyRequested","vaultEvents.WithdrawRequested","vaultEvents.RequestCancelled","builderCodeEvents.BuilderCodeSet","queueEvents.OrderEnqueued","queueEvents.CohortCommitted","queueEvents.QueuedOrderFilled","queueEvents.QueuedOrderRefunded","queueEvents.OpenRecordSettled","queueEvents.OpenRecordPayoutSkipped","queueEvents.MarketPayoutsCompleted","queueEvents.RecordFundsParked","queueEvents.RecordFundsClaimed","queueEvents.QueuedOrdersCleaned","vaultEvents.ExpiryPnlRealized"],"sources":["../../src/predict/decode.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport { fromBase64, normalizeSuiAddress } from '@mysten/sui/utils';\nimport type { PredictConfig } from './config/index.js';\nimport { accountEvents } from '../account.js';\nimport * as builderCodeEvents from '../contracts/deepbook_predict/builder_code_events.js';\nimport * as configEvents from '../contracts/deepbook_predict/config_events.js';\nimport * as orderEvents from '../contracts/deepbook_predict/order_events.js';\nimport * as vaultEvents from '../contracts/deepbook_predict/vault_events.js';\nimport * as queueEvents from '../contracts/deepbook_predict_orders/queue_events.js';\nimport { PredictInputError } from './errors.js';\nimport {\n\tisMintKind,\n\tisSellKind,\n\torderKindName,\n\tpolicyFromBcs,\n\trefundReason,\n\ttype DelayedExecutionPolicy,\n\ttype HeldPosition,\n\ttype OrderKindName,\n\ttype RefundReasonInfo,\n} from './queue.js';\nimport { decodeOrderRange } from './cost.js';\nimport { fromRaw } from './units.js';\n\n// ============================================================================\n// Execution-result decoders.\n//\n// Every tx.* builder returns a Transaction; after the app executes it (with\n// events included), the deployed contracts emit typed events carrying the full\n// receipt — order ids, fills, fees, queue indexes, new balances. These pure\n// functions turn that result into typed receipts. No network, no client.\n//\n// Decoding uses each event's BCS bytes, not its `json`: the client typings\n// warn the JSON rendering varies across transports (gRPC/GraphQL),\n// while BCS is canonical. Layouts come from the GENERATED event MoveStructs\n// (src/contracts/{deepbook_predict,deepbook_predict_orders,account}/*_events.ts), whose field order\n// mirrors the deployed Move — regenerate the bindings if the package changes.\n// ============================================================================\n\n/** The slice of an executed/simulated transaction result the decoders need. */\nexport interface DecodableEvent {\n\t/** Full type tag `0xpkg::module::Name` (gRPC `eventType`, legacy `type`). */\n\teventType?: string;\n\ttype?: string;\n\tpackageId?: string;\n\tmodule?: string;\n\t/** Struct name, when the transport supplies it separately from a full type tag. */\n\tname?: string;\n\t/** Canonical BCS payload; some transports deliver it base64-encoded. */\n\tbcs?: Uint8Array | string;\n}\n\nexport interface DecodableTransactionResult {\n\tevents?: readonly DecodableEvent[] | null;\n}\n\n// --- matching + plumbing ----------------------------------------------------\n\nfunction eventBytes(e: DecodableEvent): Uint8Array | null {\n\tif (e.bcs instanceof Uint8Array) return e.bcs;\n\tif (typeof e.bcs === 'string') return fromBase64(e.bcs);\n\treturn null;\n}\n\n// Match by defining package + module + struct name. Events are typed by the\n// package version that introduced their struct, not the latest Move-call target.\n// The pre-queue events were introduced in v1 (`predictV1`); the Predict events the\n// delayed-execution upgrade added in `predictDelayedExecution`; and the queue events\n// in the order-flow companion's original ID (`predictOrdersV1 ?? predictOrders`).\nfunction matches(e: DecodableEvent, pkg: string, module: string, name: string): boolean {\n\tconst tag = e.eventType ?? e.type;\n\tif (tag) {\n\t\tconst parts = tag.split('::');\n\t\tif (parts.length !== 3) return false;\n\t\treturn (\n\t\t\tnormalizeSuiAddress(parts[0]) === normalizeSuiAddress(pkg) &&\n\t\t\tparts[1] === module &&\n\t\t\tparts[2] === name\n\t\t);\n\t}\n\t// No type tag. Match on what the transport did give us — and on `name` when it is\n\t// present, because module+package alone matches EVERY struct in the module, so one\n\t// decoder would happily take another's event and fail deep inside BCS.\n\tif (e.module !== module || e.packageId == null) return false;\n\tif (normalizeSuiAddress(e.packageId) !== normalizeSuiAddress(pkg)) return false;\n\treturn e.name == null || e.name === name;\n}\n\nfunction decodeAll<T>(\n\tresult: DecodableTransactionResult,\n\tpkg: string,\n\tmodule: string,\n\tname: string,\n\tlayout: { parse(bytes: Uint8Array): T },\n): T[] {\n\tconst out: T[] = [];\n\tfor (const e of result.events ?? []) {\n\t\tif (!matches(e, pkg, module, name)) continue;\n\t\tconst bytes = eventBytes(e);\n\t\tif (!bytes) {\n\t\t\tthrow new PredictInputError(\n\t\t\t\t`${module}::${name} event has no BCS payload — execute/simulate with events included`,\n\t\t\t);\n\t\t}\n\t\tout.push(layout.parse(bytes));\n\t}\n\treturn out;\n}\n\nfunction exactlyOne<T>(items: T[], what: string): T {\n\tif (items.length !== 1) {\n\t\tthrow new PredictInputError(`expected exactly one ${what} event, found ${items.length}`);\n\t}\n\treturn items[0];\n}\n\nconst optId = (v: string | null | undefined): string | null =>\n\tv == null ? null : normalizeSuiAddress(v);\n\n// --- receipts ---------------------------------------------------------------\n\nexport interface MintReceipt {\n\tmarketId: string;\n\taccountId: string;\n\towner: string;\n\t/** Persist this: required to redeem/claim the position later. */\n\torderId: bigint;\n\t/** Stable across partial-close replacements; equals orderId at mint. */\n\tpositionRootId: bigint;\n\tlowerTick: bigint;\n\thigherTick: bigint;\n\t/** 0..1 range probability quoted at entry (your fill price per $1 payout). */\n\tentryProbability: number;\n\t/** Max payout actually minted, in quote units (mintAmount: chain-floored). */\n\tquantity: number;\n\t/** Premium paid into LP backing, in quote units. */\n\tpremium: number;\n\t/**\n\t * Fee breakdown. `referral` is the slice of the trader-paid trading fee and\n\t * congestion surcharge delivered to the referrer; `inventoryImpact` is the\n\t * path-independent inventory-impact charge assessed on the mint.\n\t */\n\tfees: {\n\t\ttrading: number;\n\t\tsubsidy: number;\n\t\tbuilder: number;\n\t\tpenalty: number;\n\t\treferral: number;\n\t\tinventoryImpact: number;\n\t};\n\tbuilderCodeId: string | null;\n\traw: {\n\t\tquantity: bigint;\n\t\tpremium: bigint;\n\t\ttradingFee: bigint;\n\t\tfeeIncentiveSubsidy: bigint;\n\t\tbuilderFee: bigint;\n\t\tpenaltyFee: bigint;\n\t\treferralFee: bigint;\n\t\tinventoryImpactCharge: bigint;\n\t\tentryProbability: bigint;\n\t};\n}\n\nexport interface RedeemReceipt {\n\tmarketId: string;\n\taccountId: string;\n\towner: string;\n\torderId: bigint;\n\tpositionRootId: bigint;\n\tquantityClosed: number;\n\tremaining: number;\n\t/**\n\t * A partial close RETIRES the old order id and issues this replacement for\n\t * the remaining quantity — update your stored id or it goes silently stale.\n\t */\n\treplacementOrderId: bigint | null;\n\t/** NET quote credited to the account: gross + inventoryImpactRebate − trading −\n\t * builder − penalty — the same expression the chain asserts `min_proceeds`\n\t * against, and what `settle_live_redeem_payment` actually deposits. */\n\tproceeds: number;\n\t/** Gross close value before fees (the event's redeem_amount). */\n\tgross: number;\n\t/**\n\t * Fee breakdown. `inventoryImpactRebate` is the path-independent\n\t * inventory-impact rebate credited back on the close.\n\t */\n\tfees: { trading: number; builder: number; penalty: number; inventoryImpactRebate: number };\n\tbuilderCodeId: string | null;\n\traw: {\n\t\tquantityClosed: bigint;\n\t\tremaining: bigint;\n\t\tproceeds: bigint;\n\t\tgross: bigint;\n\t\ttradingFee: bigint;\n\t\tbuilderFee: bigint;\n\t\tpenaltyFee: bigint;\n\t\tinventoryImpactRebate: bigint;\n\t};\n}\n\nexport interface ClaimReceipt {\n\tmarketId: string;\n\taccountId: string;\n\towner: string;\n\torderId: bigint;\n\tpositionRootId: bigint;\n\t/** Quote units paid out. A settled claim closes the order in full. */\n\tpayout: number;\n\traw: { payout: bigint };\n}\n\nexport interface CreateManagerReceipt {\n\taccountId: string;\n\twrapperId: string;\n\towner: string;\n\tselfOwned: boolean;\n}\n\nexport interface BalanceChangeReceipt {\n\taccountId: string;\n\tcoinType: string;\n\t/** Display value assuming a 6-decimal coin (quote + PLP both are). */\n\tamount: number;\n\tnewBalance: number;\n\traw: { amount: bigint; newBalance: bigint };\n}\n\nexport interface PlpRequestReceipt {\n\tkind: 'supply' | 'withdraw';\n\tvaultId: string;\n\taccountId: string;\n\trecipient: string;\n\t/** Feed straight into cancelSupplyPlp / cancelWithdrawPlp. */\n\tindex: bigint;\n\t/** Quote units for supply; PLP shares (6-dec) for withdraw. */\n\tamount: number;\n\traw: { amount: bigint };\n}\n\nexport interface PlpCancelReceipt {\n\tvaultId: string;\n\taccountId: string;\n\trecipient: string;\n\tindex: bigint;\n\tisSupply: boolean;\n\t/** Refund returned to the account (quote for supply, PLP for withdraw). */\n\tamount: number;\n\traw: { amount: bigint };\n}\n\nexport interface BuilderCodeReceipt {\n\taccountId: string;\n\towner: string;\n\t/** Null after unsetBuilderCode. */\n\tbuilderCodeId: string | null;\n}\n\n// --- decoders (plural = all matching events, in event order) ----------------\n\nexport function decodeMints(cfg: PredictConfig, result: DecodableTransactionResult): MintReceipt[] {\n\treturn decodeAll(\n\t\tresult,\n\t\tcfg.packages.predictV1 ?? cfg.packages.predict,\n\t\t'order_events',\n\t\t'OrderMinted',\n\t\torderEvents.OrderMinted,\n\t).map((e) => ({\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\towner: normalizeSuiAddress(e.owner),\n\t\torderId: e.order_id,\n\t\tpositionRootId: e.position_root_id,\n\t\tlowerTick: e.lower_tick,\n\t\thigherTick: e.higher_tick,\n\t\tentryProbability: fromRaw(e.entry_probability, 9),\n\t\tquantity: fromRaw(e.quantity, 6),\n\t\tpremium: fromRaw(e.premium, 6),\n\t\tfees: {\n\t\t\ttrading: fromRaw(e.trading_fee, 6),\n\t\t\tsubsidy: fromRaw(e.fee_incentive_subsidy, 6),\n\t\t\tbuilder: fromRaw(e.builder_fee, 6),\n\t\t\tpenalty: fromRaw(e.penalty_fee, 6),\n\t\t\treferral: fromRaw(e.referral_fee, 6),\n\t\t\tinventoryImpact: fromRaw(e.inventory_impact_charge, 6),\n\t\t},\n\t\tbuilderCodeId: optId(e.builder_code_id),\n\t\traw: {\n\t\t\tquantity: e.quantity,\n\t\t\tpremium: e.premium,\n\t\t\ttradingFee: e.trading_fee,\n\t\t\tfeeIncentiveSubsidy: e.fee_incentive_subsidy,\n\t\t\tbuilderFee: e.builder_fee,\n\t\t\tpenaltyFee: e.penalty_fee,\n\t\t\treferralFee: e.referral_fee,\n\t\t\tinventoryImpactCharge: e.inventory_impact_charge,\n\t\t\tentryProbability: e.entry_probability,\n\t\t},\n\t}));\n}\n\nexport function decodeRedeems(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): RedeemReceipt[] {\n\tconst pkg = cfg.packages.predictV1 ?? cfg.packages.predict;\n\tconst live = decodeAll(\n\t\tresult,\n\t\tpkg,\n\t\t'order_events',\n\t\t'LiveOrderRedeemed',\n\t\torderEvents.LiveOrderRedeemed,\n\t).map((e): RedeemReceipt => ({\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\towner: normalizeSuiAddress(e.owner),\n\t\torderId: e.order_id,\n\t\tpositionRootId: e.position_root_id,\n\t\tquantityClosed: fromRaw(e.quantity_closed, 6),\n\t\tremaining: fromRaw(e.remaining_quantity, 6),\n\t\treplacementOrderId: e.replacement_order_id,\n\t\t// Mirrors the deployed close-side accounting exactly (the same expression\n\t\t// `min_proceeds` is asserted against): the net credited to the account is\n\t\t// redeem_amount PLUS the inventory-impact rebate, minus trading, builder and\n\t\t// penalty fees. The event's redeem_amount is GROSS.\n\t\tproceeds: fromRaw(\n\t\t\te.redeem_amount + e.inventory_impact_rebate - e.trading_fee - e.builder_fee - e.penalty_fee,\n\t\t\t6,\n\t\t),\n\t\tgross: fromRaw(e.redeem_amount, 6),\n\t\tfees: {\n\t\t\ttrading: fromRaw(e.trading_fee, 6),\n\t\t\tbuilder: fromRaw(e.builder_fee, 6),\n\t\t\tpenalty: fromRaw(e.penalty_fee, 6),\n\t\t\tinventoryImpactRebate: fromRaw(e.inventory_impact_rebate, 6),\n\t\t},\n\t\tbuilderCodeId: optId(e.builder_code_id),\n\t\traw: {\n\t\t\tquantityClosed: e.quantity_closed,\n\t\t\tremaining: e.remaining_quantity,\n\t\t\tproceeds:\n\t\t\t\te.redeem_amount + e.inventory_impact_rebate - e.trading_fee - e.builder_fee - e.penalty_fee,\n\t\t\tgross: e.redeem_amount,\n\t\t\ttradingFee: e.trading_fee,\n\t\t\tbuilderFee: e.builder_fee,\n\t\t\tpenaltyFee: e.penalty_fee,\n\t\t\tinventoryImpactRebate: e.inventory_impact_rebate,\n\t\t},\n\t}));\n\treturn live;\n}\n\nexport function decodeClaims(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): ClaimReceipt[] {\n\treturn decodeAll(\n\t\tresult,\n\t\tcfg.packages.predictV1 ?? cfg.packages.predict,\n\t\t'order_events',\n\t\t'SettledOrderRedeemed',\n\t\torderEvents.SettledOrderRedeemed,\n\t).map((e) => ({\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\towner: normalizeSuiAddress(e.owner),\n\t\torderId: e.order_id,\n\t\tpositionRootId: e.position_root_id,\n\t\tpayout: fromRaw(e.payout_amount, 6),\n\t\traw: { payout: e.payout_amount },\n\t}));\n}\n\nexport function decodeAccountsCreated(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): CreateManagerReceipt[] {\n\treturn decodeAll(\n\t\tresult,\n\t\tcfg.packages.account,\n\t\t'account_events',\n\t\t'AccountCreated',\n\t\taccountEvents.AccountCreated,\n\t).map((e) => ({\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\twrapperId: normalizeSuiAddress(e.wrapper_id),\n\t\towner: normalizeSuiAddress(e.owner),\n\t\tselfOwned: e.self_owned,\n\t}));\n}\n\nfunction decodeBalanceChanges(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n\tname: 'Deposited' | 'Withdrawn',\n): BalanceChangeReceipt[] {\n\tconst layout = name === 'Deposited' ? accountEvents.Deposited : accountEvents.Withdrawn;\n\treturn decodeAll(result, cfg.packages.account, 'account_events', name, layout).map((e) => ({\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\tcoinType: e.coin_type,\n\t\tamount: fromRaw(e.amount, 6),\n\t\tnewBalance: fromRaw(e.new_balance, 6),\n\t\traw: { amount: e.amount, newBalance: e.new_balance },\n\t}));\n}\n\nexport const decodeDeposits = (\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): BalanceChangeReceipt[] => decodeBalanceChanges(cfg, result, 'Deposited');\n\nexport const decodeWithdrawals = (\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): BalanceChangeReceipt[] => decodeBalanceChanges(cfg, result, 'Withdrawn');\n\nexport function decodePlpRequests(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): PlpRequestReceipt[] {\n\tconst pkg = cfg.packages.predictV1 ?? cfg.packages.predict;\n\t// Supply/WithdrawRequested differ only in their min-out field (unused here);\n\t// pick the fields both share so either generated struct's parse feeds `make`.\n\ttype RequestedCommon = Pick<\n\t\t(typeof vaultEvents.SupplyRequested)['$inferType'],\n\t\t'pool_vault_id' | 'account_id' | 'recipient' | 'index' | 'amount'\n\t>;\n\tconst make =\n\t\t(kind: 'supply' | 'withdraw') =>\n\t\t(e: RequestedCommon): PlpRequestReceipt => ({\n\t\t\tkind,\n\t\t\tvaultId: normalizeSuiAddress(e.pool_vault_id),\n\t\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\t\trecipient: normalizeSuiAddress(e.recipient),\n\t\t\tindex: e.index,\n\t\t\tamount: fromRaw(e.amount, 6),\n\t\t\traw: { amount: e.amount },\n\t\t});\n\treturn [\n\t\t...decodeAll(result, pkg, 'vault_events', 'SupplyRequested', vaultEvents.SupplyRequested).map(\n\t\t\tmake('supply'),\n\t\t),\n\t\t...decodeAll(\n\t\t\tresult,\n\t\t\tpkg,\n\t\t\t'vault_events',\n\t\t\t'WithdrawRequested',\n\t\t\tvaultEvents.WithdrawRequested,\n\t\t).map(make('withdraw')),\n\t];\n}\n\nexport function decodePlpCancels(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): PlpCancelReceipt[] {\n\treturn decodeAll(\n\t\tresult,\n\t\tcfg.packages.predictV1 ?? cfg.packages.predict,\n\t\t'vault_events',\n\t\t'RequestCancelled',\n\t\tvaultEvents.RequestCancelled,\n\t).map((e) => ({\n\t\tvaultId: normalizeSuiAddress(e.pool_vault_id),\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\trecipient: normalizeSuiAddress(e.recipient),\n\t\tindex: e.index,\n\t\tisSupply: e.is_supply,\n\t\tamount: fromRaw(e.amount, 6),\n\t\traw: { amount: e.amount },\n\t}));\n}\n\nexport function decodeBuilderCodeSets(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): BuilderCodeReceipt[] {\n\treturn decodeAll(\n\t\tresult,\n\t\tcfg.packages.predictV1 ?? cfg.packages.predict,\n\t\t'builder_code_events',\n\t\t'BuilderCodeSet',\n\t\tbuilderCodeEvents.BuilderCodeSet,\n\t).map((e) => ({\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\towner: normalizeSuiAddress(e.owner),\n\t\tbuilderCodeId: optId(e.builder_code_id),\n\t}));\n}\n\n// --- delayed execution (DBU-885) ---------------------------------------------\n//\n// Delayed execution spans two packages. The queue events and the desk's\n// `DelayedExecutionPolicyUpdated` belong to the order-flow companion,\n// `deepbook_predict_orders` (`queue_events`), typed by its ORIGINAL ID. A fill also emits\n// Predict's `OrderMinted` or `LiveOrderRedeemed` (v1 layouts, `decodeMints`/`decodeRedeems`),\n// so match events by type, never by the package a transaction called. The Predict events the\n// delayed-execution upgrade added (`ExpiryPnlRealized`, `FlushOperatorUpdated`,\n// `OrderFlowUpdated`) are typed by `packages.predictDelayedExecution`.\n\n/**\n * The defining package of the Predict types and events the delayed-execution upgrade added.\n * Throws rather than guessing: matching against the latest package would silently decode nothing\n * once the package is upgraded again.\n */\nexport function delayedExecutionOrigin(cfg: PredictConfig): string {\n\tconst pkg = cfg.packages.predictDelayedExecution;\n\tif (!pkg) {\n\t\tthrow new PredictInputError(\n\t\t\t`delayed execution isn't recorded for ${cfg.network} in this SDK version: pass a ` +\n\t\t\t\t'`config` whose `packages.predictDelayedExecution` names the package that introduced it',\n\t\t);\n\t}\n\treturn pkg;\n}\n\n/**\n * The original ID of the order-flow companion (`deepbook_predict_orders`), which types the queue\n * events. Throws while the config doesn't record the companion.\n */\nexport function predictOrdersOrigin(cfg: PredictConfig): string {\n\tconst pkg = cfg.packages.predictOrdersV1 ?? cfg.packages.predictOrders;\n\tif (!pkg) {\n\t\tthrow new PredictInputError(\n\t\t\t`the order-flow package isn't recorded for ${cfg.network} in this SDK version: pass a ` +\n\t\t\t\t'`config` whose `packages.predictOrders` names `deepbook_predict_orders`',\n\t\t);\n\t}\n\treturn pkg;\n}\n\nfunction side(kind: number): 'mint' | 'sell' | 'unknown' {\n\treturn isMintKind(kind) ? 'mint' : isSellKind(kind) ? 'sell' : 'unknown';\n}\n\nfunction heldPosition(\n\tp: {\n\t\torder_id: bigint;\n\t\troot_id: bigint;\n\t\topened_at_ms: bigint;\n\t},\n\tlotSize: bigint,\n): HeldPosition | null {\n\treturn p.order_id === 0n\n\t\t? null\n\t\t: {\n\t\t\t\torderId: p.order_id,\n\t\t\t\trootId: p.root_id,\n\t\t\t\topenedAtMs: p.opened_at_ms,\n\t\t\t\tquantityRaw: decodeOrderRange(p.order_id, lotSize).quantity,\n\t\t\t};\n}\n\n/** The market's cash figures after the call, as the queue events report them. */\nexport interface QueueCashFigures {\n\tmarketCash: bigint;\n\trequiredCash: bigint;\n\twaitingCashNeed: bigint;\n}\n\n/** `OrderEnqueued`: the trader's own receipt for a queued mint or sell. Drives \"Placed\". */\nexport interface EnqueueReceipt {\n\ttype: 'enqueued';\n\tmarketId: string;\n\t/** The record ID: what `read.order`, `quoteSell` and `enqueueSell` take. Persist it. */\n\trecordId: bigint;\n\taccountId: string;\n\tkind: number;\n\tkindName: OrderKindName;\n\tside: 'mint' | 'sell' | 'unknown';\n\trequest: {\n\t\tlowerTick: bigint;\n\t\thigherTick: bigint;\n\t\tquantity: bigint;\n\t\tmaxPremium: bigint;\n\t\tminQuantity: bigint;\n\t\tmaxCost: bigint;\n\t\tmaxProbability: bigint;\n\t\tminProbability: bigint;\n\t\tminProceeds: bigint;\n\t};\n\t/** The position a sell moved into the record. Null for a mint. */\n\tposition: HeldPosition | null;\n\ttiming: {\n\t\tplacedAtMs: bigint;\n\t\tearliestPriceMs: bigint;\n\t\ttauMs: bigint;\n\t\tdeadlineMs: bigint;\n\t\tcutoffMs: bigint;\n\t\tpythChannel: number;\n\t};\n\t/** The Open record a sell took its position from. Null for a mint. */\n\tsourceRecordId: bigint | null;\n\tbuilderCodeId: string | null;\n\treferrerAccountId: string | null;\n\t/** USDC escrowed for the premium and fees (0 for a sell). */\n\tbudget: number;\n\torderFee: number;\n\tcash: QueueCashFigures;\n\t/** `onchain_timestamp_ms`: the placement transaction's clock. */\n\ttimestampMs: bigint;\n\traw: { budget: bigint; orderFee: bigint; cashNeed: bigint; subsidyBound: bigint };\n\t/** The volatility snapshot the fill prices with, as the generated layout parses it. */\n\tvol: (typeof queueEvents.OrderEnqueued)['$inferType']['vol'];\n}\n\n/** `CohortCommitted`: a price attached to the records `firstRecordId..=lastRecordId`. Drives \"Priced\". */\nexport interface CohortCommitReceipt {\n\ttype: 'cohort-committed';\n\tmarketId: string;\n\ttauMs: bigint;\n\t/** The update's envelope: τ, or the backup tick one channel tick later. */\n\ttickMs: bigint;\n\tfirstRecordId: bigint;\n\t/** Inclusive. */\n\tlastRecordId: bigint;\n\t/** The committed price of the cohort's first order as a float: `spotRaw / 1e9`. */\n\tprice: number;\n\t/** The committed price, normalized to 1e9. */\n\tspotRaw: bigint;\n\t/** That price's own update time, in µs. */\n\tgenerationUs: bigint;\n\tpythSourceId: number;\n\tpythChannel: number;\n\t/** Who committed: a keeper, or any third-party filler. */\n\tsender: string;\n\t/** `onchain_timestamp_ms`. */\n\ttimestampMs: bigint;\n}\n\n/** `QueuedOrderFilled`. Report \"Filled\" only from this event (or the record). */\nexport interface QueuedFillReceipt {\n\ttype: 'filled';\n\tmarketId: string;\n\trecordId: bigint;\n\taccountId: string;\n\tkind: number;\n\tside: 'mint' | 'sell' | 'unknown';\n\t/** Filled quantity (mint) or closed quantity (sell). */\n\tquantity: number;\n\t/** Cost paid (mint) or proceeds before the order fee (sell). */\n\tamount: number;\n\tfees: {\n\t\ttrading: number;\n\t\tbuilder: number;\n\t\treferral: number;\n\t\torder: number;\n\t\tsubsidyUsed: number;\n\t\tinventoryImpact: number;\n\t};\n\ttauMs: bigint;\n\ttickMs: bigint;\n\t/** The record's position now: a mint's new position, a partial sell's remainder, or null. */\n\tposition: HeldPosition | null;\n\tsender: string;\n\ttimestampMs: bigint;\n\tcash: QueueCashFigures;\n\traw: {\n\t\tquantity: bigint;\n\t\tamount: bigint;\n\t\ttradingFee: bigint;\n\t\tbuilderFee: bigint;\n\t\treferralFee: bigint;\n\t\torderFee: bigint;\n\t\tsubsidyUsed: bigint;\n\t\tinventoryImpact: bigint;\n\t};\n}\n\n/**\n * `QueuedOrderRefunded`, from whichever path refunded the order: resolve, a deadline refund, an\n * admin refund, or the settlement drain (`settle_step`, reason 5). `sender` is always the\n * transaction's sender.\n */\nexport interface QueuedRefundReceipt {\n\ttype: 'refunded';\n\tmarketId: string;\n\trecordId: bigint;\n\taccountId: string;\n\tkind: number;\n\tside: 'mint' | 'sell' | 'unknown';\n\treason: RefundReasonInfo;\n\tescrowReturned: number;\n\torderFeeReturned: number;\n\tsubsidyReturned: number;\n\t/** True when a sell's record went back to Open holding its position. */\n\tpositionReturned: boolean;\n\tsender: string;\n\ttimestampMs: bigint;\n\tcash: QueueCashFigures;\n\traw: { escrowReturned: bigint; orderFeeReturned: bigint; subsidyReturned: bigint };\n}\n\n/**\n * `OpenRecordSettled` (paid, 0 for a loser) or `OpenRecordPayoutSkipped` (stays Open, for a later\n * `pay_open`), from `settle_step`'s payout walk or `pay_open`.\n */\nexport interface OpenRecordPayoutReceipt {\n\ttype: 'open-record-settled' | 'open-record-payout-skipped';\n\tmarketId: string;\n\trecordId: bigint;\n\taccountId: string;\n\torderId: bigint;\n\tpayout: number;\n\t/** True for `OpenRecordPayoutSkipped`: the market couldn't pay it yet. */\n\tskipped: boolean;\n\ttimestampMs: bigint;\n\traw: { payout: bigint };\n}\n\n/** `MarketPayoutsCompleted`: the settlement payout walk is done. */\nexport interface MarketPayoutsCompletedReceipt {\n\ttype: 'market-payouts-completed';\n\tmarketId: string;\n\ttimestampMs: bigint;\n}\n\n/**\n * `RecordFundsParked`: a record kept USDC it couldn't send to its receive address (on USDC's deny\n * list, or USDC paused). `RecordFundsClaimed`: `claim_parked` sent a record's parked funds.\n */\nexport interface RecordFundsReceipt {\n\ttype: 'record-funds-parked' | 'record-funds-claimed';\n\tmarketId: string;\n\trecordId: bigint;\n\taccountId: string;\n\treceiveAddress: string;\n\t/** Parked: this call's parked change or refund. Claimed: everything the record had parked. */\n\tamount: number;\n\ttimestampMs: bigint;\n\traw: { amount: bigint };\n}\n\n/** Queue housekeeping events, for ops and alerts. */\nexport type QueueOpsReceipt = {\n\ttype: 'queued-orders-cleaned';\n\tmarketId: string;\n\trecordIds: bigint[];\n\ttimestampMs: bigint;\n};\n\n/** Delayed-execution admin events, for the multisig scripts and monitors. */\nexport type PolicyUpdateReceipt =\n\t| {\n\t\t\t/**\n\t\t\t * The companion desk's `DelayedExecutionPolicyUpdated`, from every policy setter with the\n\t\t\t * full post-state. The desk's `init` at publish emits none: the launch policy is only the\n\t\t\t * desk's state.\n\t\t\t */\n\t\t\ttype: 'policy-updated';\n\t\t\tdeskId: string;\n\t\t\tpolicy: DelayedExecutionPolicy;\n\t\t\ttimestampMs: bigint;\n\t  }\n\t| { type: 'flush-operator-updated'; operator: string; added: boolean; timestampMs: bigint }\n\t| {\n\t\t\t/** Predict's `OrderFlowUpdated`: an order-flow witness allowlisted or removed. */\n\t\t\ttype: 'order-flow-updated';\n\t\t\t/** The witness type, as Move's `type_name` renders it (no `0x` prefix). */\n\t\t\torderFlow: string;\n\t\t\tenabled: boolean;\n\t\t\ttimestampMs: bigint;\n\t  };\n\n/** Every delayed-execution order event, tagged, in chain order. Feed it to `queue.reduceOrderEvents`. */\nexport type QueueEvent =\n\t| EnqueueReceipt\n\t| CohortCommitReceipt\n\t| QueuedFillReceipt\n\t| QueuedRefundReceipt\n\t| OpenRecordPayoutReceipt\n\t| MarketPayoutsCompletedReceipt\n\t| RecordFundsReceipt\n\t| QueueOpsReceipt;\n\nconst cashOf = (e: { market_cash: bigint; required_cash: bigint; waiting_cash_need: bigint }) => ({\n\tmarketCash: e.market_cash,\n\trequiredCash: e.required_cash,\n\twaitingCashNeed: e.waiting_cash_need,\n});\n\nfunction enqueueReceipt(\n\te: (typeof queueEvents.OrderEnqueued)['$inferType'],\n\tlotSize: bigint,\n): EnqueueReceipt {\n\treturn {\n\t\ttype: 'enqueued',\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\trecordId: e.record_id,\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\tkind: e.kind,\n\t\tkindName: orderKindName(e.kind),\n\t\tside: side(e.kind),\n\t\trequest: {\n\t\t\tlowerTick: e.request.lower_tick,\n\t\t\thigherTick: e.request.higher_tick,\n\t\t\tquantity: e.request.quantity,\n\t\t\tmaxPremium: e.request.max_premium,\n\t\t\tminQuantity: e.request.min_quantity,\n\t\t\tmaxCost: e.request.max_cost,\n\t\t\tmaxProbability: e.request.max_probability,\n\t\t\tminProbability: e.request.min_probability,\n\t\t\tminProceeds: e.request.min_proceeds,\n\t\t},\n\t\tposition: heldPosition(e.position, lotSize),\n\t\ttiming: {\n\t\t\tplacedAtMs: e.timing.placed_at_ms,\n\t\t\tearliestPriceMs: e.timing.earliest_price_ms,\n\t\t\ttauMs: e.timing.tau_ms,\n\t\t\tdeadlineMs: e.timing.deadline_ms,\n\t\t\tcutoffMs: e.timing.cutoff_ms,\n\t\t\tpythChannel: e.timing.pyth_channel,\n\t\t},\n\t\tsourceRecordId: e.source_record_id ?? null,\n\t\tbuilderCodeId: optId(e.builder_code_id),\n\t\treferrerAccountId: optId(e.referrer_account_id),\n\t\tbudget: fromRaw(e.budget, 6),\n\t\torderFee: fromRaw(e.order_fee, 6),\n\t\tcash: cashOf(e),\n\t\ttimestampMs: e.onchain_timestamp_ms,\n\t\traw: {\n\t\t\tbudget: e.budget,\n\t\t\torderFee: e.order_fee,\n\t\t\tcashNeed: e.cash_need,\n\t\t\tsubsidyBound: e.subsidy_bound,\n\t\t},\n\t\tvol: e.vol,\n\t};\n}\n\nfunction cohortCommitReceipt(\n\te: (typeof queueEvents.CohortCommitted)['$inferType'],\n): CohortCommitReceipt {\n\treturn {\n\t\ttype: 'cohort-committed',\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\ttauMs: e.tau_ms,\n\t\ttickMs: e.tick_ms,\n\t\tfirstRecordId: e.first_record_id,\n\t\tlastRecordId: e.last_record_id,\n\t\tprice: fromRaw(e.spot, 9),\n\t\tspotRaw: e.spot,\n\t\tgenerationUs: e.generation_us,\n\t\tpythSourceId: e.pyth_source_id,\n\t\tpythChannel: e.pyth_channel,\n\t\tsender: normalizeSuiAddress(e.sender),\n\t\ttimestampMs: e.onchain_timestamp_ms,\n\t};\n}\n\nfunction fillReceipt(\n\te: (typeof queueEvents.QueuedOrderFilled)['$inferType'],\n\tlotSize: bigint,\n): QueuedFillReceipt {\n\treturn {\n\t\ttype: 'filled',\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\trecordId: e.record_id,\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\tkind: e.kind,\n\t\tside: side(e.kind),\n\t\tquantity: fromRaw(e.quantity, 6),\n\t\tamount: fromRaw(e.amount, 6),\n\t\tfees: {\n\t\t\ttrading: fromRaw(e.trading_fee, 6),\n\t\t\tbuilder: fromRaw(e.builder_fee, 6),\n\t\t\treferral: fromRaw(e.referral_fee, 6),\n\t\t\torder: fromRaw(e.order_fee, 6),\n\t\t\tsubsidyUsed: fromRaw(e.subsidy_used, 6),\n\t\t\tinventoryImpact: fromRaw(e.inventory_impact, 6),\n\t\t},\n\t\ttauMs: e.tau_ms,\n\t\ttickMs: e.tick_ms,\n\t\tposition: heldPosition(e.position, lotSize),\n\t\tsender: normalizeSuiAddress(e.sender),\n\t\ttimestampMs: e.onchain_timestamp_ms,\n\t\tcash: cashOf(e),\n\t\traw: {\n\t\t\tquantity: e.quantity,\n\t\t\tamount: e.amount,\n\t\t\ttradingFee: e.trading_fee,\n\t\t\tbuilderFee: e.builder_fee,\n\t\t\treferralFee: e.referral_fee,\n\t\t\torderFee: e.order_fee,\n\t\t\tsubsidyUsed: e.subsidy_used,\n\t\t\tinventoryImpact: e.inventory_impact,\n\t\t},\n\t};\n}\n\nfunction refundReceipt(\n\te: (typeof queueEvents.QueuedOrderRefunded)['$inferType'],\n): QueuedRefundReceipt {\n\treturn {\n\t\ttype: 'refunded',\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\trecordId: e.record_id,\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\tkind: e.kind,\n\t\tside: side(e.kind),\n\t\treason: refundReason(e.reason),\n\t\tescrowReturned: fromRaw(e.escrow_returned, 6),\n\t\torderFeeReturned: fromRaw(e.order_fee_returned, 6),\n\t\tsubsidyReturned: fromRaw(e.subsidy_returned, 6),\n\t\tpositionReturned: e.position_returned,\n\t\tsender: normalizeSuiAddress(e.sender),\n\t\ttimestampMs: e.onchain_timestamp_ms,\n\t\tcash: cashOf(e),\n\t\traw: {\n\t\t\tescrowReturned: e.escrow_returned,\n\t\t\torderFeeReturned: e.order_fee_returned,\n\t\t\tsubsidyReturned: e.subsidy_returned,\n\t\t},\n\t};\n}\n\nfunction payoutReceipt(\n\tskipped: boolean,\n): (e: (typeof queueEvents.OpenRecordSettled)['$inferType']) => OpenRecordPayoutReceipt {\n\treturn (e) => ({\n\t\ttype: skipped ? 'open-record-payout-skipped' : 'open-record-settled',\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\trecordId: e.record_id,\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\torderId: e.order_id,\n\t\tpayout: fromRaw(e.payout, 6),\n\t\tskipped,\n\t\ttimestampMs: e.onchain_timestamp_ms,\n\t\traw: { payout: e.payout },\n\t});\n}\n\nfunction recordFundsReceipt(\n\ttype: RecordFundsReceipt['type'],\n): (e: (typeof queueEvents.RecordFundsParked)['$inferType']) => RecordFundsReceipt {\n\treturn (e) => ({\n\t\ttype,\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\trecordId: e.record_id,\n\t\taccountId: normalizeSuiAddress(e.account_id),\n\t\treceiveAddress: normalizeSuiAddress(e.receive_address),\n\t\tamount: fromRaw(e.amount, 6),\n\t\ttimestampMs: e.onchain_timestamp_ms,\n\t\traw: { amount: e.amount },\n\t});\n}\n\n// Each order event the queue emits: its struct name, generated layout and receipt mapping.\n// One table drives both the per-type decoders and `decodeQueueEvents`, so they can't disagree.\nconst QUEUE_EVENT_DECODERS: readonly {\n\tname: string;\n\tlayout: { parse(bytes: Uint8Array): unknown };\n\t// `lotSize` is the config's position lot, which decodes a held position's quantity.\n\tmap: (e: never, lotSize: bigint) => QueueEvent;\n}[] = [\n\t{ name: 'OrderEnqueued', layout: queueEvents.OrderEnqueued, map: enqueueReceipt },\n\t{ name: 'CohortCommitted', layout: queueEvents.CohortCommitted, map: cohortCommitReceipt },\n\t{ name: 'QueuedOrderFilled', layout: queueEvents.QueuedOrderFilled, map: fillReceipt },\n\t{ name: 'QueuedOrderRefunded', layout: queueEvents.QueuedOrderRefunded, map: refundReceipt },\n\t{ name: 'OpenRecordSettled', layout: queueEvents.OpenRecordSettled, map: payoutReceipt(false) },\n\t{\n\t\tname: 'OpenRecordPayoutSkipped',\n\t\tlayout: queueEvents.OpenRecordPayoutSkipped,\n\t\tmap: payoutReceipt(true),\n\t},\n\t{\n\t\tname: 'MarketPayoutsCompleted',\n\t\tlayout: queueEvents.MarketPayoutsCompleted,\n\t\tmap: (e: (typeof queueEvents.MarketPayoutsCompleted)['$inferType']) => ({\n\t\t\ttype: 'market-payouts-completed',\n\t\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\t\ttimestampMs: e.onchain_timestamp_ms,\n\t\t}),\n\t},\n\t{\n\t\tname: 'RecordFundsParked',\n\t\tlayout: queueEvents.RecordFundsParked,\n\t\tmap: recordFundsReceipt('record-funds-parked'),\n\t},\n\t{\n\t\tname: 'RecordFundsClaimed',\n\t\tlayout: queueEvents.RecordFundsClaimed,\n\t\tmap: recordFundsReceipt('record-funds-claimed'),\n\t},\n\t{\n\t\tname: 'QueuedOrdersCleaned',\n\t\tlayout: queueEvents.QueuedOrdersCleaned,\n\t\tmap: (e: (typeof queueEvents.QueuedOrdersCleaned)['$inferType']) => ({\n\t\t\ttype: 'queued-orders-cleaned',\n\t\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\t\trecordIds: [...e.record_ids],\n\t\t\ttimestampMs: e.onchain_timestamp_ms,\n\t\t}),\n\t},\n];\n\nfunction eventPayload(e: DecodableEvent, module: string, name: string): Uint8Array {\n\tconst bytes = eventBytes(e);\n\tif (!bytes) {\n\t\tthrow new PredictInputError(\n\t\t\t`${module}::${name} event has no BCS payload — execute/simulate with events included`,\n\t\t);\n\t}\n\treturn bytes;\n}\n\n/**\n * Every delayed-execution order event in a result, tagged with `type`, in event order: the\n * companion's `queue_events`, matched against its original ID. The app's single entry point for\n * the queue: pass the list to `queue.reduceOrderEvents`.\n */\nexport function decodeQueueEvents(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): QueueEvent[] {\n\tconst pkg = predictOrdersOrigin(cfg);\n\tconst lotSize = BigInt(cfg.units.positionLotSize);\n\tconst out: QueueEvent[] = [];\n\tfor (const e of result.events ?? []) {\n\t\tfor (const d of QUEUE_EVENT_DECODERS) {\n\t\t\tif (!matches(e, pkg, 'queue_events', d.name)) continue;\n\t\t\tout.push(d.map(d.layout.parse(eventPayload(e, 'queue_events', d.name)) as never, lotSize));\n\t\t\tbreak;\n\t\t}\n\t}\n\treturn out;\n}\n\nfunction ofType<T extends QueueEvent['type']>(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n\t...types: T[]\n): Extract<QueueEvent, { type: T }>[] {\n\treturn decodeQueueEvents(cfg, result).filter((e): e is Extract<QueueEvent, { type: T }> =>\n\t\t(types as string[]).includes(e.type),\n\t);\n}\n\nexport const decodeEnqueues = (cfg: PredictConfig, r: DecodableTransactionResult) =>\n\tofType(cfg, r, 'enqueued');\nexport const decodeCohortCommits = (cfg: PredictConfig, r: DecodableTransactionResult) =>\n\tofType(cfg, r, 'cohort-committed');\nexport const decodeQueuedFills = (cfg: PredictConfig, r: DecodableTransactionResult) =>\n\tofType(cfg, r, 'filled');\nexport const decodeQueuedRefunds = (cfg: PredictConfig, r: DecodableTransactionResult) =>\n\tofType(cfg, r, 'refunded');\nexport const decodeOpenRecordPayouts = (cfg: PredictConfig, r: DecodableTransactionResult) =>\n\tofType(cfg, r, 'open-record-settled', 'open-record-payout-skipped');\nexport const decodeMarketPayoutsCompleted = (cfg: PredictConfig, r: DecodableTransactionResult) =>\n\tofType(cfg, r, 'market-payouts-completed');\nexport const decodeRecordFunds = (cfg: PredictConfig, r: DecodableTransactionResult) =>\n\tofType(cfg, r, 'record-funds-parked', 'record-funds-claimed');\nexport const decodeQueueOps = (cfg: PredictConfig, r: DecodableTransactionResult) =>\n\tofType(cfg, r, 'queued-orders-cleaned');\n\n/**\n * The delayed-execution admin events, in event order: the companion desk's\n * `DelayedExecutionPolicyUpdated` (matched against the companion's original ID) and Predict's\n * `FlushOperatorUpdated` and `OrderFlowUpdated` (matched against `predictDelayedExecution`).\n * Throws while the config records neither package.\n */\nexport function decodePolicyUpdates(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): PolicyUpdateReceipt[] {\n\tconst orders = predictOrdersOrigin(cfg);\n\tconst predict = delayedExecutionOrigin(cfg);\n\tconst out: PolicyUpdateReceipt[] = [];\n\tfor (const e of result.events ?? []) {\n\t\tif (matches(e, orders, 'queue_events', 'DelayedExecutionPolicyUpdated')) {\n\t\t\tconst p = queueEvents.DelayedExecutionPolicyUpdated.parse(\n\t\t\t\teventPayload(e, 'queue_events', 'DelayedExecutionPolicyUpdated'),\n\t\t\t);\n\t\t\tout.push({\n\t\t\t\ttype: 'policy-updated',\n\t\t\t\tdeskId: normalizeSuiAddress(p.desk_id),\n\t\t\t\tpolicy: policyFromBcs(p.policy),\n\t\t\t\ttimestampMs: p.onchain_timestamp_ms,\n\t\t\t});\n\t\t} else if (matches(e, predict, 'config_events', 'FlushOperatorUpdated')) {\n\t\t\tconst f = configEvents.FlushOperatorUpdated.parse(\n\t\t\t\teventPayload(e, 'config_events', 'FlushOperatorUpdated'),\n\t\t\t);\n\t\t\tout.push({\n\t\t\t\ttype: 'flush-operator-updated',\n\t\t\t\toperator: normalizeSuiAddress(f.operator),\n\t\t\t\tadded: f.added,\n\t\t\t\ttimestampMs: f.onchain_timestamp_ms,\n\t\t\t});\n\t\t} else if (matches(e, predict, 'config_events', 'OrderFlowUpdated')) {\n\t\t\tconst o = configEvents.OrderFlowUpdated.parse(\n\t\t\t\teventPayload(e, 'config_events', 'OrderFlowUpdated'),\n\t\t\t);\n\t\t\tout.push({\n\t\t\t\ttype: 'order-flow-updated',\n\t\t\t\torderFlow: o.order_flow.name,\n\t\t\t\tenabled: o.enabled,\n\t\t\t\ttimestampMs: o.onchain_timestamp_ms,\n\t\t\t});\n\t\t}\n\t}\n\treturn out;\n}\n\n/**\n * `vault_events::ExpiryPnlRealized`: the change in the pool's gross realized result on one expiry\n * since that expiry's previous emission, emitted with every `ExpiryPnl`. An expiry's first\n * emission (its first settled sweep) carries the lifetime result, which can be a loss. A later\n * one carries the extra cash a later sweep returned, always a profit. Gross: before the\n * protocol/LP split, and including the sponsor fee subsidies mints moved into expiry cash.\n */\nexport interface ExpiryPnlRealizedReceipt {\n\tvaultId: string;\n\tmarketId: string;\n\tpropbookUnderlyingId: number;\n\texpiryMs: bigint;\n\t/** The settlement price, 1e9-scaled. */\n\tsettlementPriceRaw: bigint;\n\t/** False only for a loss, which only an expiry's first emission reports. */\n\tinProfit: boolean;\n\t/** The change's magnitude, in USDC. */\n\tamount: number;\n\t/** The change with its sign: `+amount` for a profit, `−amount` for a loss. */\n\tsignedAmountRaw: bigint;\n\traw: { amount: bigint };\n}\n\n/** Every `ExpiryPnlRealized` in a result, in event order. Introduced with delayed execution. */\nexport function decodeExpiryPnlRealized(\n\tcfg: PredictConfig,\n\tresult: DecodableTransactionResult,\n): ExpiryPnlRealizedReceipt[] {\n\treturn decodeAll(\n\t\tresult,\n\t\tdelayedExecutionOrigin(cfg),\n\t\t'vault_events',\n\t\t'ExpiryPnlRealized',\n\t\tvaultEvents.ExpiryPnlRealized,\n\t).map((e) => ({\n\t\tvaultId: normalizeSuiAddress(e.pool_vault_id),\n\t\tmarketId: normalizeSuiAddress(e.expiry_market_id),\n\t\tpropbookUnderlyingId: e.propbook_underlying_id,\n\t\texpiryMs: e.expiry,\n\t\tsettlementPriceRaw: e.settlement_price,\n\t\tinProfit: e.in_profit,\n\t\tamount: fromRaw(e.amount, 6),\n\t\tsignedAmountRaw: e.in_profit ? e.amount : -e.amount,\n\t\traw: { amount: e.amount },\n\t}));\n}\n\n/**\n * The pool's gross realized P&L in raw USDC: the signed sum of `ExpiryPnlRealized` changes. Over\n * every emission of every expiry it equals the sum of each expiry's latest `ExpiryPnl`, with no\n * per-expiry dedup. Subtract the `OrderMinted.fee_incentive_subsidy` totals to isolate the\n * trading result.\n */\nexport function realizedPnlRaw(\n\treceipts: readonly Pick<ExpiryPnlRealizedReceipt, 'signedAmountRaw'>[],\n): bigint {\n\treturn receipts.reduce((sum, r)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