{"version":3,"file":"strike_payout_tree.mjs","names":["table.Table"],"sources":["../../../src/contracts/deepbook_predict/strike_payout_tree.ts"],"sourcesContent":["/**************************************************************\n * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *\n **************************************************************/\n\n/**\n * Sparse strike exposure index for payout-liability accounting.\n *\n * The tree keys finite interval boundaries by absolute tick, matching the tick\n * pair packed into the durable order ID. Raw strikes are recovered only at the\n * pricing/settlement boundary, where callers pass the owning market's `tick_size`\n * (`raw_strike = tick * tick_size`); the tree stores no grid geometry.\n *\n * This height-balanced (AVL) tree stores finite interval boundaries touched by\n * positions. Boundary ticks are caller-chosen, so the balancing rule must not read\n * anything the caller supplies: rotations are driven by measured subtree height,\n * which bounds depth at `O(log n)` for _every_ tick set rather than in expectation\n * over a random one. Depth is the cost model that matters — each node is a\n * dynamic-field child, and `apply_at` and `prefix_pay` touch one per level against\n * a per-transaction cached-object ceiling.\n *\n * It tracks each order's quantity, which is also its settled payout: a winning\n * order pays its full quantity. Live cash backing is the max-point payout plus a\n * buffer over the disjoint-book gap; the tree's max-point term is the floor anchor\n * of that enforced reserve.\n *\n * Shape carries no value for a consistent index: `combine` is associative over the\n * in-order sequence, so any arrangement of the same boundaries yields identical\n * summaries, settlement prefixes, and linear-walk totals. That holds only while\n * every prefix is non-negative, which a consistent book guarantees. Under a\n * caller/index desync the settlement walk's underflow abort depends on which\n * prefixes a given shape happens to visit, so it is not a desync detector — the\n * per-boundary underflow in `apply_net` is the authority.\n *\n * The module also owns the valuation snapshot for the resumable flush: while a\n * flush generation is active, each node lazily captures its boundary quantities\n * immediately before its first mutation under that generation (an untouched node\n * is its own snapshot), and `walk_frozen` prices the tree exactly as it stood at\n * the snapshot instant through the same walk the live read uses.\n *\n * Delayed execution adds pins: a waiting order's boundary ticks, passed in as\n * `pins` (tick -> count of waiting orders; a key is present only while its count\n * is positive). Enqueue creates the nodes up front (`ens_node`), no deletion path\n * removes a pinned node, and a resolve fill inserts over existing nodes only\n * (`ins_old`), so the keeper never creates a node.\n */\n\nimport { MoveStruct } from '../utils/index.js';\nimport { bcs } from '@mysten/sui/bcs';\nimport { U64 } from '../../bcs/integers.js';\nimport * as table from './deps/sui/table.js';\nconst $moduleName = '@local-pkg/deepbook_predict::strike_payout_tree';\nexport const StrikePayoutTree = new MoveStruct({\n\tname: `${$moduleName}::StrikePayoutTree`,\n\tfields: {\n\t\troot: bcs.option(U64),\n\t\tnodes: table.Table,\n\t\tnode_count: U64,\n\t\t/**\n\t\t * Aggregate order quantity over the open-lower prefix, which is also its aggregate\n\t\t * settled payout.\n\t\t */\n\t\tbase: U64,\n\t\t/**\n\t\t * Flush generation whose snapshot this tree holds. Node shadows are valid only\n\t\t * against this value; monotonically increasing, 0 = never snapshotted.\n\t\t */\n\t\tsnapshot_seq: U64,\n\t\t/**\n\t\t * True from `snap_on` until `snap_done`/`snap_off`. While set, mutations capture\n\t\t * shadows and emptied nodes with shadow quantities are retained for the frozen\n\t\t * walk instead of removed.\n\t\t */\n\t\tsnapshot_active: bcs.bool(),\n\t\t/** `base` as of the snapshot instant, captured eagerly at activation. */\n\t\tsnapshot_base: U64,\n\t},\n});\nexport const PayoutSummary = new MoveStruct({\n\tname: `${$moduleName}::PayoutSummary`,\n\tfields: {\n\t\tstart: U64,\n\t\tend: U64,\n\t\t/**\n\t\t * Never exceeds `start`, by construction in `bound_sum` and `combine`. That bound\n\t\t * is what makes `combine` associative at u64 scale — and therefore what makes the\n\t\t * tree's shape irrelevant to every value it reports. A summary term that could\n\t\t * outgrow `start` would break shape-independence with no test to catch it, and\n\t\t * would also abort `strike_exposure`'s plain `total - max` subtraction.\n\t\t */\n\t\tmax_payout_prefix_gain: U64,\n\t},\n});\nexport const PayoutNode = new MoveStruct({\n\tname: `${$moduleName}::PayoutNode`,\n\tfields: {\n\t\t/**\n\t\t * Longest root-to-leaf path in this subtree, counting this node. A leaf is 1; an\n\t\t * absent child is 0. Maintained by `resummarize` alongside `summary`, and read\n\t\t * only by `rebalance` — never by a caller, and never derived from a tick.\n\t\t */\n\t\theight: U64,\n\t\tleft: bcs.option(U64),\n\t\tright: bcs.option(U64),\n\t\t/**\n\t\t * This node's own boundary terms, stored so the subtree `summary` can be\n\t\t * recomputed without deriving locals by subtracting child summaries.\n\t\t */\n\t\tlocal_start: U64,\n\t\tlocal_end: U64,\n\t\t/**\n\t\t * Boundary terms at generation `snapshot_seq`'s instant, captured before the first\n\t\t * mutation under it. Active generation + zero shadows = created post-snapshot;\n\t\t * older generation = untouched, live terms ARE the shadow.\n\t\t */\n\t\tsnapshot_local_start: U64,\n\t\tsnapshot_local_end: U64,\n\t\tsnapshot_seq: U64,\n\t\tsummary: PayoutSummary,\n\t},\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkDA,MAAM,cAAc;AACpB,MAAa,mBAAmB,IAAI,WAAW;CAC9C,MAAM,GAAG,YAAY;CACrB,QAAQ;EACP,MAAM,IAAI,OAAO,IAAI;EACrB,OAAOA;EACP,YAAY;EAKZ,MAAM;EAKN,cAAc;EAMd,iBAAiB,IAAI,MAAM;EAE3B,eAAe;EACf;CACD,CAAC;AACF,MAAa,gBAAgB,IAAI,WAAW;CAC3C,MAAM,GAAG,YAAY;CACrB,QAAQ;EACP,OAAO;EACP,KAAK;EAQL,wBAAwB;EACxB;CACD,CAAC;AACF,MAAa,aAAa,IAAI,WAAW;CACxC,MAAM,GAAG,YAAY;CACrB,QAAQ;EAMP,QAAQ;EACR,MAAM,IAAI,OAAO,IAAI;EACrB,OAAO,IAAI,OAAO,IAAI;EAKtB,aAAa;EACb,WAAW;EAMX,sBAAsB;EACtB,oBAAoB;EACpB,cAAc;EACd,SAAS;EACT;CACD,CAAC"}