@mysten/deepbook-v3 1.6.7 → 2.0.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 (85) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/dist/_virtual/rolldown_runtime.mjs +18 -0
  3. package/dist/client.d.mts +9 -6
  4. package/dist/client.d.mts.map +1 -1
  5. package/dist/client.mjs +3 -2
  6. package/dist/client.mjs.map +1 -1
  7. package/dist/contracts/deepbook/account.d.mts +18 -18
  8. package/dist/contracts/deepbook/account.d.mts.map +1 -1
  9. package/dist/contracts/deepbook/deep_price.d.mts +3 -3
  10. package/dist/contracts/deepbook/deep_price.d.mts.map +1 -1
  11. package/dist/contracts/deepbook_margin/margin_manager.mjs +1 -319
  12. package/dist/contracts/deepbook_margin/margin_manager.mjs.map +1 -1
  13. package/dist/contracts/deepbook_margin/margin_manager_upgraded.mjs +386 -0
  14. package/dist/contracts/deepbook_margin/margin_manager_upgraded.mjs.map +1 -0
  15. package/dist/contracts/deepbook_margin/oracle.mjs +9 -0
  16. package/dist/contracts/deepbook_margin/oracle.mjs.map +1 -1
  17. package/dist/contracts/deepbook_margin/pool_proxy.mjs +1 -383
  18. package/dist/contracts/deepbook_margin/pool_proxy.mjs.map +1 -1
  19. package/dist/contracts/deepbook_margin/pool_proxy_upgraded.mjs +340 -0
  20. package/dist/contracts/deepbook_margin/pool_proxy_upgraded.mjs.map +1 -0
  21. package/dist/contracts/margin_liquidation/liquidation_vault.mjs +33 -17
  22. package/dist/contracts/margin_liquidation/liquidation_vault.mjs.map +1 -1
  23. package/dist/index.d.mts +4 -3
  24. package/dist/index.mjs +2 -2
  25. package/dist/pyth/PriceServiceConnection.d.mts +18 -3
  26. package/dist/pyth/PriceServiceConnection.d.mts.map +1 -1
  27. package/dist/pyth/PriceServiceConnection.mjs +35 -4
  28. package/dist/pyth/PriceServiceConnection.mjs.map +1 -1
  29. package/dist/queries/priceFeedQueries.mjs +50 -18
  30. package/dist/queries/priceFeedQueries.mjs.map +1 -1
  31. package/dist/transactions/balanceManager.d.mts +12 -12
  32. package/dist/transactions/deepbook.d.mts +20 -20
  33. package/dist/transactions/deepbookAdmin.d.mts +4 -4
  34. package/dist/transactions/deepbookAdmin.d.mts.map +1 -1
  35. package/dist/transactions/marginAdmin.d.mts +7 -7
  36. package/dist/transactions/marginAdmin.d.mts.map +1 -1
  37. package/dist/transactions/marginAdmin.mjs +2 -2
  38. package/dist/transactions/marginAdmin.mjs.map +1 -1
  39. package/dist/transactions/marginLiquidations.d.mts.map +1 -1
  40. package/dist/transactions/marginLiquidations.mjs +19 -7
  41. package/dist/transactions/marginLiquidations.mjs.map +1 -1
  42. package/dist/transactions/marginMaintainer.d.mts +5 -5
  43. package/dist/transactions/marginManager.d.mts +32 -32
  44. package/dist/transactions/marginManager.d.mts.map +1 -1
  45. package/dist/transactions/marginManager.mjs +43 -34
  46. package/dist/transactions/marginManager.mjs.map +1 -1
  47. package/dist/transactions/marginPool.d.mts +18 -18
  48. package/dist/transactions/marginTPSL.d.mts +10 -10
  49. package/dist/transactions/marginTPSL.d.mts.map +1 -1
  50. package/dist/transactions/marginTPSL.mjs +19 -10
  51. package/dist/transactions/marginTPSL.mjs.map +1 -1
  52. package/dist/transactions/poolProxy.d.mts +8 -8
  53. package/dist/transactions/poolProxy.d.mts.map +1 -1
  54. package/dist/transactions/poolProxy.mjs +34 -27
  55. package/dist/transactions/poolProxy.mjs.map +1 -1
  56. package/dist/types/index.d.mts +16 -1
  57. package/dist/types/index.d.mts.map +1 -1
  58. package/dist/types/index.mjs.map +1 -1
  59. package/dist/utils/config.d.mts +30 -10
  60. package/dist/utils/config.d.mts.map +1 -1
  61. package/dist/utils/config.mjs +33 -4
  62. package/dist/utils/config.mjs.map +1 -1
  63. package/dist/utils/constants.d.mts +32 -1
  64. package/dist/utils/constants.d.mts.map +1 -1
  65. package/dist/utils/constants.mjs +54 -23
  66. package/dist/utils/constants.mjs.map +1 -1
  67. package/package.json +1 -1
  68. package/src/client.ts +9 -1
  69. package/src/contracts/deepbook_margin/margin_manager.ts +140 -10
  70. package/src/contracts/deepbook_margin/margin_manager_upgraded.ts +651 -0
  71. package/src/contracts/deepbook_margin/oracle.ts +59 -0
  72. package/src/contracts/deepbook_margin/pool_proxy.ts +600 -584
  73. package/src/contracts/deepbook_margin/pool_proxy_upgraded.ts +614 -0
  74. package/src/contracts/margin_liquidation/liquidation_vault.ts +142 -0
  75. package/src/index.ts +4 -0
  76. package/src/pyth/PriceServiceConnection.ts +69 -8
  77. package/src/queries/priceFeedQueries.ts +74 -24
  78. package/src/transactions/marginAdmin.ts +2 -4
  79. package/src/transactions/marginLiquidations.ts +20 -6
  80. package/src/transactions/marginManager.ts +43 -33
  81. package/src/transactions/marginTPSL.ts +19 -9
  82. package/src/transactions/poolProxy.ts +34 -30
  83. package/src/types/index.ts +16 -0
  84. package/src/utils/config.ts +69 -9
  85. package/src/utils/constants.ts +88 -25
@@ -114,51 +114,6 @@ const WithdrawCollateralEvent = new MoveStruct({
114
114
  timestamp: bcs.u64()
115
115
  }
116
116
  });
117
- /**
118
- * Add a conditional order (take-profit / stop-loss). Specifies the condition under
119
- * which it triggers and the pending order to place when it does.
120
- *
121
- * Lifetime: the conditional order itself is never clamped — it rests in the queue
122
- * until it triggers or is cancelled. A _market_ pending order
123
- * (`tpsl::new_pending_market_order`) has no expiry, so it is the "until cancelled"
124
- * stop: it waits indefinitely and, when triggered, fires and deleverages via
125
- * `execute_conditional_orders_v3` (so it can protect even in the danger band). A
126
- * _limit_ pending order is intentionally transient — when it triggers, the resting
127
- * order it places is clamped to `max_order_ttl_ms` (default 3 days) by
128
- * `clamp_expire_timestamp`, the same stale-price guard as any margin limit order.
129
- * For a permanent stop, use a market pending order.
130
- */
131
- function addConditionalOrder(options) {
132
- const packageAddress = options.package ?? "@deepbook/margin";
133
- const argumentsTypes = [
134
- null,
135
- null,
136
- null,
137
- null,
138
- null,
139
- "u64",
140
- null,
141
- null,
142
- "0x2::clock::Clock"
143
- ];
144
- const parameterNames = [
145
- "self",
146
- "pool",
147
- "basePriceInfoObject",
148
- "quotePriceInfoObject",
149
- "registry",
150
- "conditionalOrderId",
151
- "condition",
152
- "pendingOrder"
153
- ];
154
- return (tx) => tx.moveCall({
155
- package: packageAddress,
156
- module: "margin_manager",
157
- function: "add_conditional_order",
158
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
159
- typeArguments: options.typeArguments
160
- });
161
- }
162
117
  /** Cancel all conditional orders. */
163
118
  function cancelAllConditionalOrders(options) {
164
119
  const packageAddress = options.package ?? "@deepbook/margin";
@@ -189,89 +144,6 @@ function cancelConditionalOrder(options) {
189
144
  typeArguments: options.typeArguments
190
145
  });
191
146
  }
192
- /**
193
- * Execute conditional orders and return the order infos. This is a permissionless
194
- * function that can be called by anyone.
195
- *
196
- * v2 adds `base_margin_pool` + `quote_margin_pool` parameters and enforces a
197
- * post-fill `risk_ratio >= min_borrow_risk_ratio` invariant inside the inner loop.
198
- * If any single triggered fill would breach that floor, the entire txn aborts — no
199
- * partial-state landing.
200
- */
201
- function executeConditionalOrdersV2(options) {
202
- const packageAddress = options.package ?? "@deepbook/margin";
203
- const argumentsTypes = [
204
- null,
205
- null,
206
- null,
207
- null,
208
- null,
209
- null,
210
- null,
211
- "u64",
212
- "0x2::clock::Clock"
213
- ];
214
- const parameterNames = [
215
- "self",
216
- "pool",
217
- "baseMarginPool",
218
- "quoteMarginPool",
219
- "basePriceInfoObject",
220
- "quotePriceInfoObject",
221
- "registry",
222
- "maxOrdersToExecute"
223
- ];
224
- return (tx) => tx.moveCall({
225
- package: packageAddress,
226
- module: "margin_manager",
227
- function: "execute_conditional_orders_v2",
228
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
229
- typeArguments: options.typeArguments
230
- });
231
- }
232
- /**
233
- * Execute conditional orders, deleveraging on each market-type fill.
234
- * Permissionless, like `execute_conditional_orders_v2`, with the same trigger and
235
- * cancellation handling — but takes the margin pools as `&mut` and repays the loan
236
- * with the market proceeds before gating on the net (post-repay) `risk_ratio`
237
- * being at least the pre-fill ratio.
238
- *
239
- * This is what lets a stop-loss fire in the `liquidation..min_borrow` danger band:
240
- * a swap alone only lowers the oracle-valued ratio (so the v2 borrow-floor gate
241
- * rejects it), while repaying actually improves it. If a single triggered fill
242
- * would worsen net solvency the whole txn aborts — no partial-state landing.
243
- */
244
- function executeConditionalOrdersV3(options) {
245
- const packageAddress = options.package ?? "@deepbook/margin";
246
- const argumentsTypes = [
247
- null,
248
- null,
249
- null,
250
- null,
251
- null,
252
- null,
253
- null,
254
- "u64",
255
- "0x2::clock::Clock"
256
- ];
257
- const parameterNames = [
258
- "self",
259
- "pool",
260
- "baseMarginPool",
261
- "quoteMarginPool",
262
- "basePriceInfoObject",
263
- "quotePriceInfoObject",
264
- "registry",
265
- "maxOrdersToExecute"
266
- ];
267
- return (tx) => tx.moveCall({
268
- package: packageAddress,
269
- module: "margin_manager",
270
- function: "execute_conditional_orders_v3",
271
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
272
- typeArguments: options.typeArguments
273
- });
274
- }
275
147
  /** Creates a new margin manager and shares it. */
276
148
  function _new(options) {
277
149
  const packageAddress = options.package ?? "@deepbook/margin";
@@ -385,131 +257,6 @@ function unsetMarginManagerReferral(options) {
385
257
  });
386
258
  }
387
259
  /**
388
- * Deposit a coin into the margin manager. The coin must be of the same type as
389
- * either the base, quote, or DEEP.
390
- */
391
- function deposit(options) {
392
- const packageAddress = options.package ?? "@deepbook/margin";
393
- const argumentsTypes = [
394
- null,
395
- null,
396
- null,
397
- null,
398
- null,
399
- "0x2::clock::Clock"
400
- ];
401
- const parameterNames = [
402
- "self",
403
- "registry",
404
- "baseOracle",
405
- "quoteOracle",
406
- "coin"
407
- ];
408
- return (tx) => tx.moveCall({
409
- package: packageAddress,
410
- module: "margin_manager",
411
- function: "deposit",
412
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
413
- typeArguments: options.typeArguments
414
- });
415
- }
416
- /**
417
- * Withdraw a specified amount of an asset from the margin manager. The asset must
418
- * be of the same type as either the base, quote, or DEEP. The withdrawal is
419
- * subject to the risk ratio limit.
420
- */
421
- function withdraw(options) {
422
- const packageAddress = options.package ?? "@deepbook/margin";
423
- const argumentsTypes = [
424
- null,
425
- null,
426
- null,
427
- null,
428
- null,
429
- null,
430
- null,
431
- "u64",
432
- "0x2::clock::Clock"
433
- ];
434
- const parameterNames = [
435
- "self",
436
- "registry",
437
- "baseMarginPool",
438
- "quoteMarginPool",
439
- "baseOracle",
440
- "quoteOracle",
441
- "pool",
442
- "withdrawAmount"
443
- ];
444
- return (tx) => tx.moveCall({
445
- package: packageAddress,
446
- module: "margin_manager",
447
- function: "withdraw",
448
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
449
- typeArguments: options.typeArguments
450
- });
451
- }
452
- /** Borrow the base asset using the margin manager. */
453
- function borrowBase(options) {
454
- const packageAddress = options.package ?? "@deepbook/margin";
455
- const argumentsTypes = [
456
- null,
457
- null,
458
- null,
459
- null,
460
- null,
461
- null,
462
- "u64",
463
- "0x2::clock::Clock"
464
- ];
465
- const parameterNames = [
466
- "self",
467
- "registry",
468
- "baseMarginPool",
469
- "baseOracle",
470
- "quoteOracle",
471
- "pool",
472
- "loanAmount"
473
- ];
474
- return (tx) => tx.moveCall({
475
- package: packageAddress,
476
- module: "margin_manager",
477
- function: "borrow_base",
478
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
479
- typeArguments: options.typeArguments
480
- });
481
- }
482
- /** Borrow the quote asset using the margin manager. */
483
- function borrowQuote(options) {
484
- const packageAddress = options.package ?? "@deepbook/margin";
485
- const argumentsTypes = [
486
- null,
487
- null,
488
- null,
489
- null,
490
- null,
491
- null,
492
- "u64",
493
- "0x2::clock::Clock"
494
- ];
495
- const parameterNames = [
496
- "self",
497
- "registry",
498
- "quoteMarginPool",
499
- "baseOracle",
500
- "quoteOracle",
501
- "pool",
502
- "loanAmount"
503
- ];
504
- return (tx) => tx.moveCall({
505
- package: packageAddress,
506
- module: "margin_manager",
507
- function: "borrow_quote",
508
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
509
- typeArguments: options.typeArguments
510
- });
511
- }
512
- /**
513
260
  * Repay the base asset loan using the margin manager. Returns the total amount
514
261
  * repaid
515
262
  */
@@ -563,35 +310,6 @@ function repayQuote(options) {
563
310
  typeArguments: options.typeArguments
564
311
  });
565
312
  }
566
- function liquidate(options) {
567
- const packageAddress = options.package ?? "@deepbook/margin";
568
- const argumentsTypes = [
569
- null,
570
- null,
571
- null,
572
- null,
573
- null,
574
- null,
575
- null,
576
- "0x2::clock::Clock"
577
- ];
578
- const parameterNames = [
579
- "self",
580
- "registry",
581
- "baseOracle",
582
- "quoteOracle",
583
- "marginPool",
584
- "pool",
585
- "repayCoin"
586
- ];
587
- return (tx) => tx.moveCall({
588
- package: packageAddress,
589
- module: "margin_manager",
590
- function: "liquidate",
591
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
592
- typeArguments: options.typeArguments
593
- });
594
- }
595
313
  function balanceManager(options) {
596
314
  const packageAddress = options.package ?? "@deepbook/margin";
597
315
  const argumentsTypes = [null];
@@ -669,42 +387,6 @@ function calculateDebts(options) {
669
387
  typeArguments: options.typeArguments
670
388
  });
671
389
  }
672
- /**
673
- * Returns comprehensive state information for a margin manager. Returns
674
- * (manager_id, deepbook_pool_id, risk_ratio, base_asset, quote_asset, base_debt,
675
- * quote_debt, base_pyth_price, base_pyth_decimals, quote_pyth_price,
676
- * quote_pyth_decimals, current_price, lowest_trigger_above_price,
677
- * highest_trigger_below_price)
678
- */
679
- function managerState(options) {
680
- const packageAddress = options.package ?? "@deepbook/margin";
681
- const argumentsTypes = [
682
- null,
683
- null,
684
- null,
685
- null,
686
- null,
687
- null,
688
- null,
689
- "0x2::clock::Clock"
690
- ];
691
- const parameterNames = [
692
- "self",
693
- "registry",
694
- "baseOracle",
695
- "quoteOracle",
696
- "pool",
697
- "baseMarginPool",
698
- "quoteMarginPool"
699
- ];
700
- return (tx) => tx.moveCall({
701
- package: packageAddress,
702
- module: "margin_manager",
703
- function: "manager_state",
704
- arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
705
- typeArguments: options.typeArguments
706
- });
707
- }
708
390
  function owner(options) {
709
391
  const packageAddress = options.package ?? "@deepbook/margin";
710
392
  const argumentsTypes = [null];
@@ -985,5 +667,5 @@ function canPlaceMarketOrder(options) {
985
667
  }
986
668
 
987
669
  //#endregion
988
- export { _new, account, accountExists, accountOpenOrders, addConditionalOrder, balanceManager, balanceManagerId, baseBalance, borrowBase, borrowQuote, borrowedBaseShares, borrowedQuoteShares, borrowedShares, calculateAssets, calculateDebts, canPlaceLimitOrder, canPlaceMarketOrder, cancelAllConditionalOrders, cancelConditionalOrder, conditionalOrder, conditionalOrderIds, deepBalance, deepbookPool, deposit, executeConditionalOrdersV2, executeConditionalOrdersV3, getAccountOrderDetails, getBalanceManagerReferralId, hasBaseDebt, highestTriggerBelowPrice, liquidate, lockedBalance, lowestTriggerAbovePrice, managerState, marginPoolId, newWithInitializer, owner, quoteBalance, registerMarginManager, repayBase, repayQuote, setMarginManagerReferral, share, unregisterMarginManager, unsetMarginManagerReferral, withdraw };
670
+ export { _new, account, accountExists, accountOpenOrders, balanceManager, balanceManagerId, baseBalance, borrowedBaseShares, borrowedQuoteShares, borrowedShares, calculateAssets, calculateDebts, canPlaceLimitOrder, canPlaceMarketOrder, cancelAllConditionalOrders, cancelConditionalOrder, conditionalOrder, conditionalOrderIds, deepBalance, deepbookPool, getAccountOrderDetails, getBalanceManagerReferralId, hasBaseDebt, highestTriggerBelowPrice, lockedBalance, lowestTriggerAbovePrice, marginPoolId, newWithInitializer, owner, quoteBalance, registerMarginManager, repayBase, repayQuote, setMarginManagerReferral, share, unregisterMarginManager, unsetMarginManagerReferral };
989
671
  //# sourceMappingURL=margin_manager.mjs.map