{"version":3,"file":"trade.mjs","names":["expiryMarketBindings.redeemSettled","expiryMarket.loadLivePricer","account.generateAuth","expiryMarket.mintExactQuantity","expiryMarket.mintExactAmount","expiryMarket.mintExactCost","expiryMarket.redeemLive"],"sources":["../../../src/predict/tx/trade.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\nimport type { Transaction, TransactionResult } from '@mysten/sui/transactions';\nimport type { GeneratedConfig } from '../config/generated.js';\nimport { U64_MAX } from '../units.js';\nimport { accountMoveCalls as account } from '../../account.js';\nimport * as expiryMarket from '../../contracts/deepbook_predict/expiry_market.js';\nimport * as expiryMarketBindings from '../bindings/expiry-market.js';\nimport { withAuth } from './common.js';\n\n// The trade calls with their `auth` argument already supplied (see `withAuth`): each\n// takes its generated options minus that slot and expands to auth → call.\nconst authed = {\n\t// The shipped argument keys: Predict v5 underscore-prefixed the retired call's parameters.\n\tredeemSettled: withAuth(expiryMarketBindings.redeemSettled),\n};\n\n// The oracle feed object ids a live market's pricer reads. Grouped so callers pass one\n// bundle; the deployment's per-underlying ids live in `cfg.underlyings[symbol]` (see\n// `src/config/testnet.ts`), named to match `deployment.testnet.json`.\nexport interface MarketFeeds {\n\tpythFeed: string;\n\tblockScholesValueStore: string;\n\tblockScholesSviStore: string;\n}\n\n// Load a fresh `Pricer` from the live oracle feeds. Every live-flow trade call\n// (`mint_*`, `redeem_live`) and every live quote (`quote_mint*`, the queue's `quote_redeem_open`) borrows\n// this `&Pricer` and it must be loaded first in the PTB. Queued orders (`enqueue_*`) don't take\n// one: they read the oracle objects directly. Deployed sig `load_live_pricer` (expiry_market.move): market, config,\n// propbook_registry (&OracleRegistry), pyth, bs_values, bs_svi, clock (auto-injected).\n// `config` and `propbook_registry` are supplied by the config slice, not named here.\nexport function loadLivePricer(\n\tconfig: GeneratedConfig,\n\targs: { expiryMarketId: string } & MarketFeeds,\n): (tx: Transaction) => TransactionResult {\n\treturn (tx) =>\n\t\ttx.add(\n\t\t\texpiryMarket.loadLivePricer({\n\t\t\t\tconfig,\n\t\t\t\targuments: {\n\t\t\t\t\tmarket: args.expiryMarketId,\n\t\t\t\t\tpyth: args.pythFeed,\n\t\t\t\t\tbsValues: args.blockScholesValueStore,\n\t\t\t\t\tbsSvi: args.blockScholesSviStore,\n\t\t\t\t},\n\t\t\t}),\n\t\t);\n}\n\n// The three commands every live-flow trade is: load a fresh market-bound `Pricer`, mint\n// owner auth, then the one `expiry_market::*` call that consumes both.\n//\n// The live trades are retired: Predict v4 keeps their published signatures but names every\n// parameter with a leading underscore, which codegen renders as a capitalized key (`_market` →\n// `Market`). So the auth is minted here and passed as `Auth`, rather than through `withAuth`.\n// The emitted commands are unchanged, and still reach a pre-v4 package.\nfunction liveTrade(\n\tconfig: GeneratedConfig,\n\targs: { expiryMarketId: string } & MarketFeeds,\n\tbuild: (\n\t\tpricer: TransactionResult,\n\t\tauth: TransactionResult,\n\t) => (tx: Transaction) => TransactionResult,\n): (tx: Transaction) => TransactionResult {\n\treturn (tx) => {\n\t\tconst pricer = tx.add(loadLivePricer(config, args));\n\t\tconst auth = tx.add(account.generateAuth({ config }));\n\t\treturn tx.add(build(pricer, auth));\n\t};\n}\n\n// Mint a position of an exact `quantityRaw`, capped by cost/probability ceilings,\n// returning the new order id (u256). Command order is pricer → auth → mint (auth is a\n// hot potato consumed by this call). `maxCostRaw`/`maxProbabilityRaw` default to\n// `U64_MAX` (no slippage cap). Deployed sig `mint_exact_quantity`.\n/**\n * @deprecated Retired by delayed execution (DBU-885): Predict v4's `mint_exact_quantity` always\n * aborts `EDelayedExecutionRequired`, so this works only while the config's call target is a\n * pre-v4 package. Use `enqueueExactQuantity` from `tx/queue.ts`.\n */\nexport function mintExactQuantity(\n\tconfig: GeneratedConfig,\n\targs: {\n\t\texpiryMarketId: string;\n\t\twrapperId: string;\n\t\tlowerTick: bigint;\n\t\thigherTick: bigint;\n\t\tquantityRaw: bigint;\n\t\tmaxCostRaw?: bigint;\n\t\tmaxProbabilityRaw?: bigint;\n\t} & MarketFeeds,\n): (tx: Transaction) => TransactionResult {\n\treturn liveTrade(config, args, (pricer, auth) =>\n\t\texpiryMarket.mintExactQuantity({\n\t\t\tconfig,\n\t\t\targuments: {\n\t\t\t\tMarket: args.expiryMarketId,\n\t\t\t\tWrapper: args.wrapperId,\n\t\t\t\tAuth: auth,\n\t\t\t\tPricer: pricer,\n\t\t\t\tLowerTick: args.lowerTick,\n\t\t\t\tHigherTick: args.higherTick,\n\t\t\t\tQuantity: args.quantityRaw,\n\t\t\t\tMaxCost: args.maxCostRaw ?? U64_MAX,\n\t\t\t\tMaxProbability: args.maxProbabilityRaw ?? U64_MAX,\n\t\t\t},\n\t\t}),\n\t);\n}\n\n// Mint by spending up to `maxPremiumRaw` (raw quote units), enforcing a `minQuantityRaw`\n// floor on the position received and a `maxCostRaw` all-in ceiling, returning the new\n// order id (u256). Command order is pricer → auth → mint. Deployed sig\n// `mint_exact_amount`: …, max_premium, min_quantity, max_cost, root.\n/**\n * @deprecated Retired by delayed execution (DBU-885): Predict v4 always aborts it\n * (`EDelayedExecutionRequired`). Use `enqueueExactAmount`.\n */\nexport function mintExactAmount(\n\tconfig: GeneratedConfig,\n\targs: {\n\t\texpiryMarketId: string;\n\t\twrapperId: string;\n\t\tlowerTick: bigint;\n\t\thigherTick: bigint;\n\t\tmaxPremiumRaw: bigint;\n\t\tminQuantityRaw: bigint;\n\t\tmaxCostRaw?: bigint;\n\t} & MarketFeeds,\n): (tx: Transaction) => TransactionResult {\n\treturn liveTrade(config, args, (pricer, auth) =>\n\t\texpiryMarket.mintExactAmount({\n\t\t\tconfig,\n\t\t\targuments: {\n\t\t\t\tMarket: args.expiryMarketId,\n\t\t\t\tWrapper: args.wrapperId,\n\t\t\t\tAuth: auth,\n\t\t\t\tPricer: pricer,\n\t\t\t\tLowerTick: args.lowerTick,\n\t\t\t\tHigherTick: args.higherTick,\n\t\t\t\tMaxPremium: args.maxPremiumRaw,\n\t\t\t\tMinQuantity: args.minQuantityRaw,\n\t\t\t\tMaxCost: args.maxCostRaw ?? U64_MAX,\n\t\t\t},\n\t\t}),\n\t);\n}\n\n/**\n * Mint within an all-in budget, including fees, using the v2 entrypoint.\n * @deprecated Retired by delayed execution (DBU-885): Predict v4 always aborts it\n * (`EDelayedExecutionRequired`). Use `enqueueExactCost`.\n */\nexport function mintExactCost(\n\tconfig: GeneratedConfig,\n\targs: {\n\t\texpiryMarketId: string;\n\t\twrapperId: string;\n\t\tlowerTick: bigint;\n\t\thigherTick: bigint;\n\t\tmaxCostRaw: bigint;\n\t\tminQuantityRaw: bigint;\n\t} & MarketFeeds,\n): (tx: Transaction) => TransactionResult {\n\treturn liveTrade(config, args, (pricer, auth) =>\n\t\texpiryMarket.mintExactCost({\n\t\t\tconfig,\n\t\t\targuments: {\n\t\t\t\tMarket: args.expiryMarketId,\n\t\t\t\tWrapper: args.wrapperId,\n\t\t\t\tAuth: auth,\n\t\t\t\tPricer: pricer,\n\t\t\t\tLowerTick: args.lowerTick,\n\t\t\t\tHigherTick: args.higherTick,\n\t\t\t\tMaxCost: args.maxCostRaw,\n\t\t\t\tMinQuantity: args.minQuantityRaw,\n\t\t\t},\n\t\t}),\n\t);\n}\n\n// Owner-authorized redeem of a live (not-yet-settled) position: close `closeQuantityRaw`\n// of `orderId` at the live pricer's mark, enforcing close-side slippage floors\n// (`minProbabilityRaw`/`minProceedsRaw`, default 0 = uncapped). Returns `Option<u256>`:\n// the replacement order id when a partial close leaves quantity open, else none. Command\n// order is pricer → auth → redeem. Deployed sig `redeem_live`.\n/**\n * @deprecated Retired by delayed execution (DBU-885): Predict v4 always aborts it\n * (`EDelayedExecutionRequired`). Account positions then have no early exit; queued fills are Open\n * records sold with `enqueueRedeemOpen`.\n */\nexport function redeemLive(\n\tconfig: GeneratedConfig,\n\targs: {\n\t\texpiryMarketId: string;\n\t\twrapperId: string;\n\t\torderId: bigint;\n\t\tcloseQuantityRaw: bigint;\n\t\tminProbabilityRaw?: bigint;\n\t\tminProceedsRaw?: bigint;\n\t} & MarketFeeds,\n): (tx: Transaction) => TransactionResult {\n\treturn liveTrade(config, args, (pricer, auth) =>\n\t\texpiryMarket.redeemLive({\n\t\t\tconfig,\n\t\t\targuments: {\n\t\t\t\tMarket: args.expiryMarketId,\n\t\t\t\tWrapper: args.wrapperId,\n\t\t\t\tAuth: auth,\n\t\t\t\tPricer: pricer,\n\t\t\t\tOrderId: args.orderId,\n\t\t\t\tCloseQuantity: args.closeQuantityRaw,\n\t\t\t\tMinProbability: args.minProbabilityRaw ?? 0n,\n\t\t\t\tMinProceeds: args.minProceedsRaw ?? 0n,\n\t\t\t},\n\t\t}),\n\t);\n}\n\n// Unchanged by delayed execution: still pays settled positions held in the account. It doesn't\n// pay Open queue records, which the queue's `settle_step` pays at settlement.\n//\n// Owner-authorized redeem of a settled position: closes `orderId` IN FULL against the\n// recorded settlement price (the deployed entrypoint takes no quantity — a settled claim\n// is all-or-nothing). No live pricer (settlement price is fixed); auth is consumed by the\n// call. Deployed sig `redeem_settled` (owner-auth form). The keeper-facing\n// `redeem_settled_permissionless` is a separate entrypoint, out of scope for this SDK.\nexport function redeemSettled(\n\tconfig: GeneratedConfig,\n\targs: {\n\t\texpiryMarketId: string;\n\t\twrapperId: string;\n\t\torderId: bigint;\n\t},\n): (tx: Transaction) => TransactionResult {\n\treturn authed.redeemSettled({\n\t\tconfig,\n\t\targuments: {\n\t\t\tmarket: args.expiryMarketId,\n\t\t\twrapper: args.wrapperId,\n\t\t\torderId: args.orderId,\n\t\t},\n\t});\n}\n"],"mappings":";;;;;;;AAYA,MAAM,SAAS,EAEd,eAAe,SAASA,gBAAmC,EAC3D;AAiBD,SAAgB,eACf,QACA,MACyC;AACzC,SAAQ,OACP,GAAG,IACFC,iBAA4B;EAC3B;EACA,WAAW;GACV,QAAQ,KAAK;GACb,MAAM,KAAK;GACX,UAAU,KAAK;GACf,OAAO,KAAK;GACZ;EACD,CAAC,CACF;;AAUH,SAAS,UACR,QACA,MACA,OA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