{"version":3,"file":"pricing.mjs","names":["i64.I64"],"sources":["../../../src/contracts/deepbook_predict/pricing.ts"],"sourcesContent":["/**************************************************************\n * THIS FILE IS GENERATED AND SHOULD NOT BE MANUALLY MODIFIED *\n **************************************************************/\n\n/**\n * Pricing for Predict markets.\n *\n * This module reads canonical Propbook Pyth and Block Scholes feeds and computes\n * SVI-adjusted digital probabilities. Live reads require fresh, pricing-safe Block\n * Scholes spot, forward, and SVI observations. The latest forward is paired with\n * an exact source-timestamp spot from Propbook's bounded recent history. The live\n * forward comes from one of two admin-selected sources\n * (`PricingConfig.use_pyth_spot_for_forward`): a fresh positive Pyth spot carrying\n * the Block Scholes basis, or the Block Scholes forward directly. A load falls\n * back to the Block Scholes forward when the selected Pyth spot is stale or\n * unavailable; valuation prices on that fallback, while every live trade (mints,\n * mint quotes, and live redeems) refuses it through `assert_pyth_spot_fresh`.\n * Exact-history reads do not apply live freshness policy.\n *\n * Delayed execution splits that read in two. `load_vol` validates the same live\n * inputs when an order is admitted and returns the raw Block Scholes basis and SVI\n * its receipt stores; `pricer_at` later rebuilds a `Pricer` from them at the\n * order's committed Pyth tick. The `try_*` reads price exactly as `up_price` and\n * `range_price` do, and return `none` where those abort, so an order-flow fill\n * never aborts on a surface.\n *\n * A Propbook SVI store signs its parameters at the decimals the admin set on it,\n * `9` or `18`. Every load prices `a` and `b` at 1e18 either way, exactly when the\n * store is at 18. A receipt's snapshot keeps them at 1e9, so an admission at 18\n * also records the full-precision tuple in its market's SVI cache, a dynamic field\n * this module keeps on the market's UID (`SviKey`), and the fill prices from that\n * entry when it still holds it.\n */\n\nimport { MoveStruct, MoveTuple, normalizeMoveArguments } from '../utils/index.js';\nimport { bcs } from '@mysten/sui/bcs';\nimport { U64, U128 } from '../../bcs/integers.js';\nimport { type Transaction, type TransactionArgument } from '@mysten/sui/transactions';\nimport * as i64 from './deps/fixed_math/i64.js';\nconst $moduleName = '@local-pkg/deepbook_predict::pricing';\nexport const VolSnapshot = new MoveStruct({\n\tname: `${$moduleName}::VolSnapshot`,\n\tfields: {\n\t\t/**\n\t\t * Canonical Propbook Pyth source for the market's underlying; commit finds this\n\t\t * feed in each Lazer update.\n\t\t */\n\t\tpyth_source_id: bcs.u32(),\n\t\t/** The matched Block Scholes spot and forward, narrowed to Predict's width. */\n\t\tbs_spot: U64,\n\t\tbs_forward: U64,\n\t\t/** Raw SVI parameters before roll-down, at 1e9. */\n\t\tsvi_a: i64.I64,\n\t\tsvi_b: U64,\n\t\tsvi_rho: i64.I64,\n\t\tsvi_m: i64.I64,\n\t\tsvi_sigma: U64,\n\t\t/**\n\t\t * Provider source timestamps of the three reads. The SVI one is also the roll-down\n\t\t * anchor.\n\t\t */\n\t\tbs_spot_source_timestamp_ms: U64,\n\t\tbs_forward_source_timestamp_ms: U64,\n\t\tsvi_source_timestamp_ms: U64,\n\t},\n});\nexport const PricingSVI = new MoveStruct({\n\tname: `${$moduleName}::PricingSVI`,\n\tfields: {\n\t\t/** SVI `a`, magnitude at 1e18, sign in `a_is_negative`. */\n\t\ta_magnitude: U128,\n\t\ta_is_negative: bcs.bool(),\n\t\t/** SVI `b`, at 1e18. */\n\t\tb: U128,\n\t\trho: i64.I64,\n\t\tm: i64.I64,\n\t\tsigma: U64,\n\t},\n});\nexport const FrozenPricer = new MoveStruct({\n\tname: `${$moduleName}::FrozenPricer`,\n\tfields: {\n\t\texpiry_market_id: bcs.Address,\n\t\tforward: U64,\n\t\tsvi: PricingSVI,\n\t\tpyth_spot_source_timestamp_ms: U64,\n\t\tblock_scholes_spot_source_timestamp_ms: U64,\n\t\tblock_scholes_forward_source_timestamp_ms: U64,\n\t\tblock_scholes_svi_source_timestamp_ms: U64,\n\t},\n});\nexport const Pricer = new MoveStruct({\n\tname: `${$moduleName}::Pricer`,\n\tfields: {\n\t\t/** Expiry market this snapshot was loaded for. */\n\t\texpiry_market_id: bcs.Address,\n\t\tforward: U64,\n\t\tsvi: PricingSVI,\n\t\t/**\n\t\t * Timestamps of the oracle observations this snapshot validated, as trade events\n\t\t * report them — each observation's own economic clock. Pyth carries its source\n\t\t * timestamp (`0` only when no usable normalized observation exists; a `pricer_at`\n\t\t * Pricer carries the committed update's generation time); Block Scholes spot and\n\t\t * forward carry the provider `value_timestamp`, and SVI carries the provider\n\t\t * `svi_timestamp`. Those timestamps are the clocks freshness gates and SVI\n\t\t * roll-down use. The Pyth timestamp, including its `0` sentinel, is also what\n\t\t * `assert_pyth_spot_fresh` gates live trades on, so it must stay the value the\n\t\t * load's forward selection read.\n\t\t */\n\t\tpyth_spot_source_timestamp_ms: U64,\n\t\tblock_scholes_spot_source_timestamp_ms: U64,\n\t\tblock_scholes_forward_source_timestamp_ms: U64,\n\t\tblock_scholes_svi_source_timestamp_ms: U64,\n\t},\n});\nexport const RangePrice = new MoveStruct({\n\tname: `${$moduleName}::RangePrice`,\n\tfields: {\n\t\tlower_up: bcs.option(U64),\n\t\thigher_up: bcs.option(U64),\n\t},\n});\nexport const RawSVI = new MoveStruct({\n\tname: `${$moduleName}::RawSVI`,\n\tfields: {\n\t\ta: i64.I64,\n\t\tb: U64,\n\t\trho: i64.I64,\n\t\tm: i64.I64,\n\t\tsigma: U64,\n\t},\n});\nexport const SviKey = new MoveTuple({ name: `${$moduleName}::SviKey`, fields: [bcs.bool()] });\nexport interface UpPriceArguments {\n\tpricer: TransactionArgument;\n\tstrike: TransactionArgument;\n}\nexport interface UpPriceOptions {\n\tpackage?: string;\n\targuments: UpPriceArguments | [pricer: TransactionArgument, strike: TransactionArgument];\n\tconfig?: {\n\t\tpredictPackageId?: string;\n\t};\n}\n/**\n * Return the current UP digital probability for a typed strike. Public PTB and\n * devInspect reads can compose it with a transaction-local `Pricer`.\n */\nexport function upPrice(options: UpPriceOptions) {\n\tconst packageAddress =\n\t\toptions.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';\n\tconst argumentsTypes = [null, null] satisfies (string | null)[];\n\tconst parameterNames = ['pricer', 'strike'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'pricing',\n\t\t\tfunction: 'up_price',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t});\n}\nexport interface RangePriceArguments {\n\tpricer: TransactionArgument;\n\tlower: TransactionArgument;\n\thigher: TransactionArgument;\n}\nexport interface RangePriceOptions {\n\tpackage?: string;\n\targuments:\n\t\t| RangePriceArguments\n\t\t| [pricer: TransactionArgument, lower: TransactionArgument, higher: TransactionArgument];\n\tconfig?: {\n\t\tpredictPackageId?: string;\n\t};\n}\n/**\n * Return both boundary probabilities for `(lower, higher]`. Use `probability()`\n * for the combined range probability; absent boundaries are infinite sentinels.\n */\nexport function rangePrice(options: RangePriceOptions) {\n\tconst packageAddress =\n\t\toptions.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';\n\tconst argumentsTypes = [null, null, null] satisfies (string | null)[];\n\tconst parameterNames = ['pricer', 'lower', 'higher'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'pricing',\n\t\t\tfunction: 'range_price',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t});\n}\nexport interface LowerUpArguments {\n\tprice: TransactionArgument;\n}\nexport interface LowerUpOptions {\n\tpackage?: string;\n\targuments: LowerUpArguments | [price: TransactionArgument];\n\tconfig?: {\n\t\tpredictPackageId?: string;\n\t};\n}\nexport function lowerUp(options: LowerUpOptions) {\n\tconst packageAddress =\n\t\toptions.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';\n\tconst argumentsTypes = [null] satisfies (string | null)[];\n\tconst parameterNames = ['price'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'pricing',\n\t\t\tfunction: 'lower_up',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t});\n}\nexport interface HigherUpArguments {\n\tprice: TransactionArgument;\n}\nexport interface HigherUpOptions {\n\tpackage?: string;\n\targuments: HigherUpArguments | [price: TransactionArgument];\n\tconfig?: {\n\t\tpredictPackageId?: string;\n\t};\n}\nexport function higherUp(options: HigherUpOptions) {\n\tconst packageAddress =\n\t\toptions.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';\n\tconst argumentsTypes = [null] satisfies (string | null)[];\n\tconst parameterNames = ['price'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'pricing',\n\t\t\tfunction: 'higher_up',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t});\n}\nexport interface ProbabilityArguments {\n\tprice: TransactionArgument;\n}\nexport interface ProbabilityOptions {\n\tpackage?: string;\n\targuments: ProbabilityArguments | [price: TransactionArgument];\n\tconfig?: {\n\t\tpredictPackageId?: string;\n\t};\n}\n/**\n * Return the combined probability, floored at zero if approximated boundary prices\n * invert.\n */\nexport function probability(options: ProbabilityOptions) {\n\tconst packageAddress =\n\t\toptions.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';\n\tconst argumentsTypes = [null] satisfies (string | null)[];\n\tconst parameterNames = ['price'];\n\treturn (tx: Transaction) =>\n\t\ttx.moveCall({\n\t\t\tpackage: packageAddress,\n\t\t\tmodule: 'pricing',\n\t\t\tfunction: 'probability',\n\t\t\targuments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),\n\t\t});\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,MAAM,cAAc;AACpB,MAAa,cAAc,IAAI,WAAW;CACzC,MAAM,GAAG,YAAY;CACrB,QAAQ;EAKP,gBAAgB,IAAI,KAAK;EAEzB,SAAS;EACT,YAAY;EAEZ,OAAOA;EACP,OAAO;EACP,SAASA;EACT,OAAOA;EACP,WAAW;E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