@mysten/deepbook-v3 2.1.4 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/PREDICT.md +17 -5
  3. package/dist/account.d.mts.map +1 -1
  4. package/dist/account.mjs +3 -1
  5. package/dist/account.mjs.map +1 -1
  6. package/dist/client.d.mts +2 -2
  7. package/dist/contracts/account/account_events.d.mts +20 -20
  8. package/dist/contracts/deepbook/account.d.mts +18 -18
  9. package/dist/contracts/deepbook/balances.d.mts +4 -4
  10. package/dist/contracts/deepbook/order.d.mts +12 -12
  11. package/dist/contracts/deepbook_predict/deps/sui/vec_map.mjs +37 -0
  12. package/dist/contracts/deepbook_predict/deps/sui/vec_map.mjs.map +1 -0
  13. package/dist/contracts/deepbook_predict/expiry_cash.mjs +1 -1
  14. package/dist/contracts/deepbook_predict/expiry_cash.mjs.map +1 -1
  15. package/dist/contracts/deepbook_predict/expiry_market.mjs +15 -6
  16. package/dist/contracts/deepbook_predict/expiry_market.mjs.map +1 -1
  17. package/dist/contracts/deepbook_predict/market_manager.mjs.map +1 -1
  18. package/dist/contracts/deepbook_predict/order_events.mjs.map +1 -1
  19. package/dist/contracts/deepbook_predict/plp.mjs +53 -31
  20. package/dist/contracts/deepbook_predict/plp.mjs.map +1 -1
  21. package/dist/contracts/deepbook_predict/pool_accounting.mjs +7 -7
  22. package/dist/contracts/deepbook_predict/pool_accounting.mjs.map +1 -1
  23. package/dist/contracts/deepbook_predict/predict_account.mjs +1 -1
  24. package/dist/contracts/deepbook_predict/predict_account.mjs.map +1 -1
  25. package/dist/contracts/deepbook_predict/pricing.mjs +13 -1
  26. package/dist/contracts/deepbook_predict/pricing.mjs.map +1 -1
  27. package/dist/contracts/deepbook_predict/registry.mjs +2 -1
  28. package/dist/contracts/deepbook_predict/registry.mjs.map +1 -1
  29. package/dist/contracts/deepbook_predict/strike_exposure.mjs.map +1 -1
  30. package/dist/contracts/deepbook_predict/strike_payout_tree.mjs +13 -1
  31. package/dist/contracts/deepbook_predict/strike_payout_tree.mjs.map +1 -1
  32. package/dist/contracts/deepbook_predict/vault_events.mjs +19 -7
  33. package/dist/contracts/deepbook_predict/vault_events.mjs.map +1 -1
  34. package/dist/contracts/deepbook_sessions/session_config.d.mts +8 -8
  35. package/dist/contracts/deepbook_sessions/session_config.d.mts.map +1 -1
  36. package/dist/contracts/deepbook_sessions/sessions.d.mts +22 -22
  37. package/dist/contracts/deepbook_sessions/sessions.d.mts.map +1 -1
  38. package/dist/deployments/index.d.mts +3 -2
  39. package/dist/deployments/index.d.mts.map +1 -1
  40. package/dist/deployments/index.mjs +4 -1
  41. package/dist/deployments/index.mjs.map +1 -1
  42. package/dist/deployments/mainnet.d.mts +14 -0
  43. package/dist/deployments/mainnet.d.mts.map +1 -0
  44. package/dist/deployments/mainnet.mjs +73 -0
  45. package/dist/deployments/mainnet.mjs.map +1 -0
  46. package/dist/deployments/testnet.mjs +23 -23
  47. package/dist/deployments/testnet.mjs.map +1 -1
  48. package/dist/deployments/types.d.mts +1 -1
  49. package/dist/predict/client.d.mts +25 -4
  50. package/dist/predict/client.d.mts.map +1 -1
  51. package/dist/predict/client.mjs +4 -4
  52. package/dist/predict/client.mjs.map +1 -1
  53. package/dist/predict/config/index.d.mts +2 -0
  54. package/dist/predict/config/index.d.mts.map +1 -1
  55. package/dist/predict/config/index.mjs +4 -1
  56. package/dist/predict/config/index.mjs.map +1 -1
  57. package/dist/predict/config/mainnet.d.mts +17 -0
  58. package/dist/predict/config/mainnet.d.mts.map +1 -0
  59. package/dist/predict/config/mainnet.mjs +26 -0
  60. package/dist/predict/config/mainnet.mjs.map +1 -0
  61. package/dist/predict/config/types.d.mts +6 -0
  62. package/dist/predict/config/types.d.mts.map +1 -1
  63. package/dist/predict/index.d.mts +4 -2
  64. package/dist/predict/index.mjs +3 -1
  65. package/dist/predict/pricing.d.mts +6 -6
  66. package/dist/predict/pricing.d.mts.map +1 -1
  67. package/dist/predict/pricing.mjs +6 -6
  68. package/dist/predict/pricing.mjs.map +1 -1
  69. package/dist/predict/reads/balances.mjs.map +1 -1
  70. package/dist/predict/reads/markets.mjs +1 -1
  71. package/dist/predict/reads/markets.mjs.map +1 -1
  72. package/dist/predict/reads/pricing.d.mts +2 -1
  73. package/dist/predict/reads/pricing.d.mts.map +1 -1
  74. package/dist/predict/reads/pricing.mjs.map +1 -1
  75. package/dist/sessions.d.mts.map +1 -1
  76. package/dist/sessions.mjs +3 -1
  77. package/dist/sessions.mjs.map +1 -1
  78. package/dist/transactions/balanceManager.d.mts +12 -12
  79. package/dist/transactions/balanceManager.d.mts.map +1 -1
  80. package/dist/transactions/deepbook.d.mts +20 -20
  81. package/dist/transactions/deepbook.d.mts.map +1 -1
  82. package/dist/transactions/deepbookAdmin.d.mts +4 -4
  83. package/dist/transactions/deepbookAdmin.d.mts.map +1 -1
  84. package/dist/transactions/marginAdmin.d.mts +7 -7
  85. package/dist/transactions/marginLiquidations.d.mts +3 -3
  86. package/dist/transactions/marginMaintainer.d.mts +5 -5
  87. package/dist/transactions/marginManager.d.mts +32 -32
  88. package/dist/transactions/marginPool.d.mts +18 -18
  89. package/dist/transactions/marginPool.d.mts.map +1 -1
  90. package/dist/transactions/marginRegistry.d.mts +16 -16
  91. package/dist/transactions/marginTPSL.d.mts +10 -10
  92. package/dist/transactions/poolProxy.d.mts +8 -8
  93. package/package.json +3 -3
  94. package/src/account.ts +3 -1
  95. package/src/contracts/deepbook_predict/builder_code.ts +3 -3
  96. package/src/contracts/deepbook_predict/config_events.ts +9 -2
  97. package/src/contracts/deepbook_predict/deps/sui/vec_map.ts +33 -0
  98. package/src/contracts/deepbook_predict/expiry_cash.ts +1 -1
  99. package/src/contracts/deepbook_predict/expiry_market.ts +70 -11
  100. package/src/contracts/deepbook_predict/market_lifecycle_cap.ts +3 -10
  101. package/src/contracts/deepbook_predict/market_manager.ts +2 -2
  102. package/src/contracts/deepbook_predict/order_events.ts +6 -6
  103. package/src/contracts/deepbook_predict/plp.ts +263 -81
  104. package/src/contracts/deepbook_predict/pool_accounting.ts +14 -14
  105. package/src/contracts/deepbook_predict/pool_valuation_cap.ts +69 -0
  106. package/src/contracts/deepbook_predict/predict_account.ts +1 -1
  107. package/src/contracts/deepbook_predict/pricing.ts +16 -4
  108. package/src/contracts/deepbook_predict/protocol_config.ts +202 -7
  109. package/src/contracts/deepbook_predict/registry.ts +91 -17
  110. package/src/contracts/deepbook_predict/strike_exposure.ts +1 -1
  111. package/src/contracts/deepbook_predict/strike_payout_tree.ts +27 -0
  112. package/src/contracts/deepbook_predict/vault_events.ts +45 -14
  113. package/src/contracts/propbook/block_scholes_store.ts +8 -42
  114. package/src/deployments/index.ts +13 -3
  115. package/src/deployments/mainnet.ts +107 -0
  116. package/src/deployments/testnet.ts +25 -25
  117. package/src/deployments/types.ts +1 -1
  118. package/src/predict/client.ts +45 -15
  119. package/src/predict/config/index.ts +7 -2
  120. package/src/predict/config/mainnet.ts +27 -0
  121. package/src/predict/config/types.ts +7 -1
  122. package/src/predict/index.ts +5 -0
  123. package/src/predict/pricing.ts +11 -9
  124. package/src/predict/reads/balances.ts +1 -1
  125. package/src/predict/reads/markets.ts +1 -1
  126. package/src/predict/reads/pricing.ts +2 -1
  127. package/src/sessions.ts +4 -1
@@ -19,14 +19,24 @@ import {
19
19
  type RawTransactionArgument,
20
20
  type ConfigValue,
21
21
  } from '../utils/index.js';
22
- import { bcs } from '@mysten/sui/bcs';
23
22
  import { U64 } from '../../bcs/integers.js';
23
+ import { bcs } from '@mysten/sui/bcs';
24
24
  import { type Transaction, type TransactionArgument } from '@mysten/sui/transactions';
25
25
  import * as expiry_cash from './expiry_cash.js';
26
26
  import * as balance from './deps/sui/balance.js';
27
27
  import * as strike_exposure from './strike_exposure.js';
28
28
  import * as ewma from './ewma.js';
29
29
  const $moduleName = '@local-pkg/deepbook_predict::expiry_market';
30
+ export const ValuationStamp = new MoveStruct({
31
+ name: `${$moduleName}::ValuationStamp`,
32
+ fields: {
33
+ flush_seq: U64,
34
+ /** `cash.balance()` at the snapshot instant. */
35
+ snapshot_cash: U64,
36
+ /** `cash.inventory_impact_reserve()` at the snapshot instant. */
37
+ snapshot_impact_reserve: U64,
38
+ },
39
+ });
30
40
  export const ExpiryMarket = new MoveStruct({
31
41
  name: `${$moduleName}::ExpiryMarket`,
32
42
  fields: {
@@ -34,9 +44,9 @@ export const ExpiryMarket = new MoveStruct({
34
44
  /** Propbook underlying this market was created for. */
35
45
  propbook_underlying_id: bcs.u32(),
36
46
  expiry: U64,
37
- /** DUSDC custody and payout backing. */
47
+ /** USDC custody and payout backing. */
38
48
  cash: expiry_cash.ExpiryCash,
39
- /** Sponsor-funded DUSDC available to subsidize this market's taker fees. */
49
+ /** Sponsor-funded USDC available to subsidize this market's taker fees. */
40
50
  fee_incentive_balance: balance.Balance,
41
51
  /** Exposure lifecycle state for this expiry's strike ticks. */
42
52
  strike_exposure: strike_exposure.StrikeExposure,
@@ -48,6 +58,14 @@ export const ExpiryMarket = new MoveStruct({
48
58
  * through the registry (ungated kill switch).
49
59
  */
50
60
  mint_paused: bcs.bool(),
61
+ /**
62
+ * `Some` from the flush's snapshot stage until this market's `value_expiry` (or
63
+ * lazily discarded once the stamp goes stale — see `ValuationStamp`). Trading is
64
+ * never gated on it and never touches it: the cash rows are captured eagerly here
65
+ * at the snapshot instant, and the payout tree captures its own boundary shadows
66
+ * as trades first touch each node.
67
+ */
68
+ valuation_stamp: bcs.option(ValuationStamp),
51
69
  },
52
70
  });
53
71
  export const MintQuote = new MoveStruct({
@@ -224,7 +242,7 @@ export interface CashBalanceOptions {
224
242
  predictPackageId?: string;
225
243
  };
226
244
  }
227
- /** Return expiry DUSDC custody for SDK and devInspect state reads. */
245
+ /** Return expiry USDC custody for SDK and devInspect state reads. */
228
246
  export function cashBalance(options: CashBalanceOptions) {
229
247
  const packageAddress =
230
248
  options.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';
@@ -396,7 +414,7 @@ export interface InventoryImpactScaleOptions {
396
414
  };
397
415
  }
398
416
  /**
399
- * Return the immutable DUSDC scale of this market's inventory-impact curve for SDK
417
+ * Return the immutable USDC scale of this market's inventory-impact curve for SDK
400
418
  * and devInspect state reads.
401
419
  */
402
420
  export function inventoryImpactScale(options: InventoryImpactScaleOptions) {
@@ -614,6 +632,45 @@ export function loadLivePricer(options: LoadLivePricerOptions) {
614
632
  ),
615
633
  });
616
634
  }
635
+ export interface IsPendingValuationArguments {
636
+ market: RawTransactionArgument<string>;
637
+ config?: RawTransactionArgument<string>;
638
+ }
639
+ export interface IsPendingValuationOptions {
640
+ package?: string;
641
+ arguments: IsPendingValuationArguments;
642
+ config?: {
643
+ protocolConfig: ConfigValue;
644
+ predictPackageId?: string;
645
+ };
646
+ }
647
+ /**
648
+ * Return whether this market is snapshotted into the in-flight flush and still
649
+ * awaiting its `value_expiry`. For SDK, keeper, and devInspect reads. It gates
650
+ * nothing: settlement and trading both run regardless — the frozen mark is
651
+ * settlement-invariant, so a stamped market settles the instant it expires. Do not
652
+ * defer a settlement attempt on this read.
653
+ */
654
+ export function isPendingValuation(options: IsPendingValuationOptions) {
655
+ const packageAddress =
656
+ options.package ?? options.config?.predictPackageId ?? '@local-pkg/deepbook_predict';
657
+ const argumentsTypes = [null, null] satisfies (string | null)[];
658
+ const parameterNames = ['market', 'config'];
659
+ return (tx: Transaction) =>
660
+ tx.moveCall({
661
+ package: packageAddress,
662
+ module: 'expiry_market',
663
+ function: 'is_pending_valuation',
664
+ arguments: normalizeMoveArguments(
665
+ {
666
+ ...options.arguments,
667
+ config: options.arguments?.config ?? options.config?.protocolConfig,
668
+ },
669
+ argumentsTypes,
670
+ parameterNames,
671
+ ),
672
+ });
673
+ }
617
674
  export interface CurrentNavArguments {
618
675
  market: RawTransactionArgument<string>;
619
676
  pricer: TransactionArgument;
@@ -1118,7 +1175,7 @@ export interface MintExactQuantityOptions {
1118
1175
  * withdraw through the loaded account. The position's strike range is the tick
1119
1176
  * pair `(lower_tick, higher_tick]` (`lower_tick = 0` is `-inf`,
1120
1177
  * `higher_tick = pos_inf_tick` is `+inf`); the SDK converts raw strikes to ticks.
1121
- * `max_cost` caps the all-in DUSDC withdrawal, while `max_probability` caps the
1178
+ * `max_cost` caps the all-in USDC withdrawal, while `max_probability` caps the
1122
1179
  * quoted per-contract probability before fees. Callers can pass
1123
1180
  * `std::u64::max_value!()` for either uncapped guard. Returns the minted order ID
1124
1181
  * for future order-scoped flows.
@@ -1193,12 +1250,12 @@ export interface MintExactAmountOptions {
1193
1250
  * must meet `min_quantity`.
1194
1251
  *
1195
1252
  * Fees, builder fees, and EWMA congestion penalties are charged on top of
1196
- * `max_premium`, so `max_cost` — not `max_premium` — bounds the all-in DUSDC
1253
+ * `max_premium`, so `max_cost` — not `max_premium` — bounds the all-in USDC
1197
1254
  * withdrawal (`premium + trader-paid fee + builder_fee + EWMA penalty`).
1198
1255
  * `max_cost` is required: unlike `mint_exact_quantity`'s guards there is no value
1199
1256
  * that disables it, because the budget shape exists to bound spend. The sizing
1200
- * budget is first capped to the account's available DUSDC after settlement; fees
1201
- * still require additional available DUSDC at payment time. Any unspent premium
1257
+ * budget is first capped to the account's available USDC after settlement; fees
1258
+ * still require additional available USDC at payment time. Any unspent premium
1202
1259
  * dust remains in the account because order quantity must be an integer number of
1203
1260
  * `position_lot_size` lots.
1204
1261
  */
@@ -1275,7 +1332,7 @@ export interface RedeemLiveOptions {
1275
1332
  * Two close-side slippage floors, the mirror of mint's `max_probability` /
1276
1333
  * `max_cost` pair; pass `0` to disable either. `min_probability` floors the quoted
1277
1334
  * per-contract range probability (same units as mint's `max_probability`).
1278
- * `min_proceeds` floors the all-in net DUSDC credited to the account
1335
+ * `min_proceeds` floors the all-in net USDC credited to the account
1279
1336
  * (`redeem_amount` minus trading fee, builder fee, and EWMA penalty), the mirror
1280
1337
  * of mint's all-in `max_cost`.
1281
1338
  */
@@ -1440,7 +1497,9 @@ export interface SetReferenceTickOptions {
1440
1497
  * Set this expiry's reference fine-grid tick from the exact previous-window
1441
1498
  * Propbook Pyth observation. The source observation must be inserted into the feed
1442
1499
  * at `reference_tick_source_timestamp_ms` before this call, and the normalized
1443
- * spot is floored to the market's `tick_size`.
1500
+ * spot is floored to the market's `tick_size`. Not gated on the valuation lock:
1501
+ * the reference tick shapes mint admission only, and a mint it admits mid-flush is
1502
+ * invisible to the captured snapshot like any other.
1444
1503
  */
1445
1504
  export function setReferenceTick(options: SetReferenceTickOptions) {
1446
1505
  const packageAddress =
@@ -3,10 +3,9 @@
3
3
  **************************************************************/
4
4
 
5
5
  /**
6
- * Defines revocable authority for market creation and coordinated pool valuation
7
- * without granting oracle-write or root-admin power. `Registry` owns the allowlist
8
- * and converts a valid capability into the ability-less proof consumed by
9
- * cross-module lifecycle flows.
6
+ * Defines revocable authority for market creation without granting pool-valuation,
7
+ * oracle-write, or root-admin power. `Registry` owns the allowlist and the
8
+ * creation entrypoint this capability gates.
10
9
  */
11
10
 
12
11
  import { MoveStruct, normalizeMoveArguments, type RawTransactionArgument } from '../utils/index.js';
@@ -19,12 +18,6 @@ export const MarketLifecycleCap = new MoveStruct({
19
18
  id: bcs.Address,
20
19
  },
21
20
  });
22
- export const MarketLifecycleProof = new MoveStruct({
23
- name: `${$moduleName}::MarketLifecycleProof`,
24
- fields: {
25
- dummy_field: bcs.bool(),
26
- },
27
- });
28
21
  export interface IdArguments {
29
22
  cap: RawTransactionArgument<string>;
30
23
  }
@@ -40,12 +40,12 @@ export const CadenceConfig = new MoveStruct({
40
40
  /** Coarser raw-price step that new finite mint boundaries must align to. */
41
41
  admission_tick_size: U64,
42
42
  /**
43
- * DUSDC pool allocation cap snapshotted into pool accounting for each created
43
+ * USDC pool allocation cap snapshotted into pool accounting for each created
44
44
  * expiry.
45
45
  */
46
46
  max_expiry_allocation: U64,
47
47
  /**
48
- * Minimum DUSDC cash target snapshotted into pool accounting for each created
48
+ * Minimum USDC cash target snapshotted into pool accounting for each created
49
49
  * expiry.
50
50
  */
51
51
  initial_expiry_cash: U64,
@@ -36,14 +36,14 @@ export const OrderMinted = new MoveStruct({
36
36
  /** 1e9-scaled range probability quoted at entry. */
37
37
  entry_probability: U64,
38
38
  quantity: U64,
39
- /** Premium the user paid into LP backing, in DUSDC base units. */
39
+ /** Premium the user paid into LP backing, in USDC base units. */
40
40
  premium: U64,
41
41
  /** Full trading fee assessed for the mint, including any sponsor-paid subsidy. */
42
42
  trading_fee: U64,
43
43
  /** Portion of `trading_fee` paid from expiry-local fee incentives. */
44
44
  fee_incentive_subsidy: U64,
45
45
  builder_fee: U64,
46
- /** EWMA gas-price congestion surcharge assessed for the mint, in DUSDC base units. */
46
+ /** EWMA gas-price congestion surcharge assessed for the mint, in USDC base units. */
47
47
  penalty_fee: U64,
48
48
  /**
49
49
  * Portion of the trader-paid trading fee and congestion surcharge delivered to the
@@ -62,8 +62,8 @@ export const OrderMinted = new MoveStruct({
62
62
  onchain_timestamp_ms: U64,
63
63
  /**
64
64
  * Oracle source timestamps present when this mint was priced: Pyth's canonical
65
- * source time and the Block Scholes batch-envelope times used for freshness. The
66
- * SVI one is also the roll-down anchor. Pyth is `0` only when unusable.
65
+ * source time and the Block Scholes per-update source times used for freshness.
66
+ * The SVI one is also the roll-down anchor. Pyth is `0` only when unusable.
67
67
  */
68
68
  pyth_spot_source_timestamp_ms: U64,
69
69
  block_scholes_spot_source_timestamp_ms: U64,
@@ -92,7 +92,7 @@ export const LiveOrderRedeemed = new MoveStruct({
92
92
  redeem_amount: U64,
93
93
  trading_fee: U64,
94
94
  builder_fee: U64,
95
- /** EWMA gas-price congestion surcharge retained by the pool, in DUSDC base units. */
95
+ /** EWMA gas-price congestion surcharge retained by the pool, in USDC base units. */
96
96
  penalty_fee: U64,
97
97
  /** Separate inventory-impact rebate paid from its isolated escrow. */
98
98
  inventory_impact_rebate: U64,
@@ -104,7 +104,7 @@ export const LiveOrderRedeemed = new MoveStruct({
104
104
  onchain_timestamp_ms: U64,
105
105
  /**
106
106
  * Oracle source timestamps present when this redemption was priced: Pyth's
107
- * canonical source time and the Block Scholes batch-envelope times used for
107
+ * canonical source time and the Block Scholes per-update source times used for
108
108
  * freshness. The SVI one is also the roll-down anchor. Pyth is `0` only when
109
109
  * unusable.
110
110
  */