@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.
- package/CHANGELOG.md +52 -0
- package/dist/_virtual/rolldown_runtime.mjs +18 -0
- package/dist/client.d.mts +9 -6
- package/dist/client.d.mts.map +1 -1
- package/dist/client.mjs +3 -2
- package/dist/client.mjs.map +1 -1
- package/dist/contracts/deepbook/account.d.mts +18 -18
- package/dist/contracts/deepbook/account.d.mts.map +1 -1
- package/dist/contracts/deepbook/deep_price.d.mts +3 -3
- package/dist/contracts/deepbook/deep_price.d.mts.map +1 -1
- package/dist/contracts/deepbook_margin/margin_manager.mjs +1 -319
- package/dist/contracts/deepbook_margin/margin_manager.mjs.map +1 -1
- package/dist/contracts/deepbook_margin/margin_manager_upgraded.mjs +386 -0
- package/dist/contracts/deepbook_margin/margin_manager_upgraded.mjs.map +1 -0
- package/dist/contracts/deepbook_margin/oracle.mjs +9 -0
- package/dist/contracts/deepbook_margin/oracle.mjs.map +1 -1
- package/dist/contracts/deepbook_margin/pool_proxy.mjs +1 -383
- package/dist/contracts/deepbook_margin/pool_proxy.mjs.map +1 -1
- package/dist/contracts/deepbook_margin/pool_proxy_upgraded.mjs +340 -0
- package/dist/contracts/deepbook_margin/pool_proxy_upgraded.mjs.map +1 -0
- package/dist/contracts/margin_liquidation/liquidation_vault.mjs +33 -17
- package/dist/contracts/margin_liquidation/liquidation_vault.mjs.map +1 -1
- package/dist/index.d.mts +4 -3
- package/dist/index.mjs +2 -2
- package/dist/pyth/PriceServiceConnection.d.mts +18 -3
- package/dist/pyth/PriceServiceConnection.d.mts.map +1 -1
- package/dist/pyth/PriceServiceConnection.mjs +35 -4
- package/dist/pyth/PriceServiceConnection.mjs.map +1 -1
- package/dist/queries/priceFeedQueries.mjs +50 -18
- package/dist/queries/priceFeedQueries.mjs.map +1 -1
- package/dist/transactions/balanceManager.d.mts +12 -12
- package/dist/transactions/deepbook.d.mts +20 -20
- package/dist/transactions/deepbookAdmin.d.mts +4 -4
- package/dist/transactions/deepbookAdmin.d.mts.map +1 -1
- package/dist/transactions/marginAdmin.d.mts +7 -7
- package/dist/transactions/marginAdmin.d.mts.map +1 -1
- package/dist/transactions/marginAdmin.mjs +2 -2
- package/dist/transactions/marginAdmin.mjs.map +1 -1
- package/dist/transactions/marginLiquidations.d.mts.map +1 -1
- package/dist/transactions/marginLiquidations.mjs +19 -7
- package/dist/transactions/marginLiquidations.mjs.map +1 -1
- package/dist/transactions/marginMaintainer.d.mts +5 -5
- package/dist/transactions/marginManager.d.mts +32 -32
- package/dist/transactions/marginManager.d.mts.map +1 -1
- package/dist/transactions/marginManager.mjs +43 -34
- package/dist/transactions/marginManager.mjs.map +1 -1
- package/dist/transactions/marginPool.d.mts +18 -18
- package/dist/transactions/marginTPSL.d.mts +10 -10
- package/dist/transactions/marginTPSL.d.mts.map +1 -1
- package/dist/transactions/marginTPSL.mjs +19 -10
- package/dist/transactions/marginTPSL.mjs.map +1 -1
- package/dist/transactions/poolProxy.d.mts +8 -8
- package/dist/transactions/poolProxy.d.mts.map +1 -1
- package/dist/transactions/poolProxy.mjs +34 -27
- package/dist/transactions/poolProxy.mjs.map +1 -1
- package/dist/types/index.d.mts +16 -1
- package/dist/types/index.d.mts.map +1 -1
- package/dist/types/index.mjs.map +1 -1
- package/dist/utils/config.d.mts +30 -10
- package/dist/utils/config.d.mts.map +1 -1
- package/dist/utils/config.mjs +33 -4
- package/dist/utils/config.mjs.map +1 -1
- package/dist/utils/constants.d.mts +32 -1
- package/dist/utils/constants.d.mts.map +1 -1
- package/dist/utils/constants.mjs +54 -23
- package/dist/utils/constants.mjs.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +9 -1
- package/src/contracts/deepbook_margin/margin_manager.ts +140 -10
- package/src/contracts/deepbook_margin/margin_manager_upgraded.ts +651 -0
- package/src/contracts/deepbook_margin/oracle.ts +59 -0
- package/src/contracts/deepbook_margin/pool_proxy.ts +600 -584
- package/src/contracts/deepbook_margin/pool_proxy_upgraded.ts +614 -0
- package/src/contracts/margin_liquidation/liquidation_vault.ts +142 -0
- package/src/index.ts +4 -0
- package/src/pyth/PriceServiceConnection.ts +69 -8
- package/src/queries/priceFeedQueries.ts +74 -24
- package/src/transactions/marginAdmin.ts +2 -4
- package/src/transactions/marginLiquidations.ts +20 -6
- package/src/transactions/marginManager.ts +43 -33
- package/src/transactions/marginTPSL.ts +19 -9
- package/src/transactions/poolProxy.ts +34 -30
- package/src/types/index.ts +16 -0
- package/src/utils/config.ts +69 -9
- package/src/utils/constants.ts +88 -25
|
@@ -23,7 +23,10 @@ export interface UpdateCurrentPriceOptions {
|
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* Updates the current price for a pool using safe oracle price calculation. Anyone
|
|
26
|
-
* can call this to update the price oracle used for order validation.
|
|
26
|
+
* can call this to update the price oracle used for order validation. Updates the
|
|
27
|
+
* current price for a pool using safe oracle price calculation. Anyone can call
|
|
28
|
+
* this to update the price oracle used for order validation. Twin:
|
|
29
|
+
* `pool_proxy_upgraded::update_current_price`. Edit both.
|
|
27
30
|
*/
|
|
28
31
|
export function updateCurrentPrice(options: UpdateCurrentPriceOptions) {
|
|
29
32
|
const packageAddress = options.package ?? '@deepbook/margin';
|
|
@@ -306,744 +309,354 @@ export function placeReduceOnlyMarketOrder(options: PlaceReduceOnlyMarketOrderOp
|
|
|
306
309
|
typeArguments: options.typeArguments,
|
|
307
310
|
});
|
|
308
311
|
}
|
|
309
|
-
export interface
|
|
312
|
+
export interface ModifyOrderArguments {
|
|
310
313
|
registry: RawTransactionArgument<string>;
|
|
311
314
|
marginManager: RawTransactionArgument<string>;
|
|
312
315
|
pool: RawTransactionArgument<string>;
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
baseOracle: RawTransactionArgument<string>;
|
|
316
|
-
quoteOracle: RawTransactionArgument<string>;
|
|
317
|
-
clientOrderId: RawTransactionArgument<number | bigint>;
|
|
318
|
-
orderType: RawTransactionArgument<number>;
|
|
319
|
-
selfMatchingOption: RawTransactionArgument<number>;
|
|
320
|
-
price: RawTransactionArgument<number | bigint>;
|
|
321
|
-
quantity: RawTransactionArgument<number | bigint>;
|
|
322
|
-
isBid: RawTransactionArgument<boolean>;
|
|
323
|
-
payWithDeep: RawTransactionArgument<boolean>;
|
|
324
|
-
expireTimestamp: RawTransactionArgument<number | bigint>;
|
|
316
|
+
orderId: RawTransactionArgument<number | bigint>;
|
|
317
|
+
newQuantity: RawTransactionArgument<number | bigint>;
|
|
325
318
|
}
|
|
326
|
-
export interface
|
|
319
|
+
export interface ModifyOrderOptions {
|
|
327
320
|
package?: string;
|
|
328
321
|
arguments:
|
|
329
|
-
|
|
|
322
|
+
| ModifyOrderArguments
|
|
330
323
|
| [
|
|
331
324
|
registry: RawTransactionArgument<string>,
|
|
332
325
|
marginManager: RawTransactionArgument<string>,
|
|
333
326
|
pool: RawTransactionArgument<string>,
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
baseOracle: RawTransactionArgument<string>,
|
|
337
|
-
quoteOracle: RawTransactionArgument<string>,
|
|
338
|
-
clientOrderId: RawTransactionArgument<number | bigint>,
|
|
339
|
-
orderType: RawTransactionArgument<number>,
|
|
340
|
-
selfMatchingOption: RawTransactionArgument<number>,
|
|
341
|
-
price: RawTransactionArgument<number | bigint>,
|
|
342
|
-
quantity: RawTransactionArgument<number | bigint>,
|
|
343
|
-
isBid: RawTransactionArgument<boolean>,
|
|
344
|
-
payWithDeep: RawTransactionArgument<boolean>,
|
|
345
|
-
expireTimestamp: RawTransactionArgument<number | bigint>,
|
|
327
|
+
orderId: RawTransactionArgument<number | bigint>,
|
|
328
|
+
newQuantity: RawTransactionArgument<number | bigint>,
|
|
346
329
|
];
|
|
347
330
|
typeArguments: [string, string];
|
|
348
331
|
}
|
|
349
|
-
/**
|
|
350
|
-
export function
|
|
332
|
+
/** Modifies an order */
|
|
333
|
+
export function modifyOrder(options: ModifyOrderOptions) {
|
|
351
334
|
const packageAddress = options.package ?? '@deepbook/margin';
|
|
352
|
-
const argumentsTypes = [
|
|
353
|
-
|
|
354
|
-
null
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
null,
|
|
358
|
-
null,
|
|
359
|
-
null,
|
|
360
|
-
'u64',
|
|
361
|
-
'u8',
|
|
362
|
-
'u8',
|
|
363
|
-
'u64',
|
|
364
|
-
'u64',
|
|
365
|
-
'bool',
|
|
366
|
-
'bool',
|
|
367
|
-
'u64',
|
|
368
|
-
'0x2::clock::Clock',
|
|
369
|
-
] satisfies (string | null)[];
|
|
370
|
-
const parameterNames = [
|
|
371
|
-
'registry',
|
|
372
|
-
'marginManager',
|
|
373
|
-
'pool',
|
|
374
|
-
'baseMarginPool',
|
|
375
|
-
'quoteMarginPool',
|
|
376
|
-
'baseOracle',
|
|
377
|
-
'quoteOracle',
|
|
378
|
-
'clientOrderId',
|
|
379
|
-
'orderType',
|
|
380
|
-
'selfMatchingOption',
|
|
381
|
-
'price',
|
|
382
|
-
'quantity',
|
|
383
|
-
'isBid',
|
|
384
|
-
'payWithDeep',
|
|
385
|
-
'expireTimestamp',
|
|
386
|
-
];
|
|
335
|
+
const argumentsTypes = [null, null, null, 'u128', 'u64', '0x2::clock::Clock'] satisfies (
|
|
336
|
+
| string
|
|
337
|
+
| null
|
|
338
|
+
)[];
|
|
339
|
+
const parameterNames = ['registry', 'marginManager', 'pool', 'orderId', 'newQuantity'];
|
|
387
340
|
return (tx: Transaction) =>
|
|
388
341
|
tx.moveCall({
|
|
389
342
|
package: packageAddress,
|
|
390
343
|
module: 'pool_proxy',
|
|
391
|
-
function: '
|
|
344
|
+
function: 'modify_order',
|
|
392
345
|
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
393
346
|
typeArguments: options.typeArguments,
|
|
394
347
|
});
|
|
395
348
|
}
|
|
396
|
-
export interface
|
|
349
|
+
export interface CancelOrderArguments {
|
|
397
350
|
registry: RawTransactionArgument<string>;
|
|
398
351
|
marginManager: RawTransactionArgument<string>;
|
|
399
352
|
pool: RawTransactionArgument<string>;
|
|
400
|
-
|
|
401
|
-
quoteMarginPool: RawTransactionArgument<string>;
|
|
402
|
-
baseOracle: RawTransactionArgument<string>;
|
|
403
|
-
quoteOracle: RawTransactionArgument<string>;
|
|
404
|
-
clientOrderId: RawTransactionArgument<number | bigint>;
|
|
405
|
-
selfMatchingOption: RawTransactionArgument<number>;
|
|
406
|
-
quantity: RawTransactionArgument<number | bigint>;
|
|
407
|
-
isBid: RawTransactionArgument<boolean>;
|
|
408
|
-
payWithDeep: RawTransactionArgument<boolean>;
|
|
353
|
+
orderId: RawTransactionArgument<number | bigint>;
|
|
409
354
|
}
|
|
410
|
-
export interface
|
|
355
|
+
export interface CancelOrderOptions {
|
|
411
356
|
package?: string;
|
|
412
357
|
arguments:
|
|
413
|
-
|
|
|
358
|
+
| CancelOrderArguments
|
|
414
359
|
| [
|
|
415
360
|
registry: RawTransactionArgument<string>,
|
|
416
361
|
marginManager: RawTransactionArgument<string>,
|
|
417
362
|
pool: RawTransactionArgument<string>,
|
|
418
|
-
|
|
419
|
-
quoteMarginPool: RawTransactionArgument<string>,
|
|
420
|
-
baseOracle: RawTransactionArgument<string>,
|
|
421
|
-
quoteOracle: RawTransactionArgument<string>,
|
|
422
|
-
clientOrderId: RawTransactionArgument<number | bigint>,
|
|
423
|
-
selfMatchingOption: RawTransactionArgument<number>,
|
|
424
|
-
quantity: RawTransactionArgument<number | bigint>,
|
|
425
|
-
isBid: RawTransactionArgument<boolean>,
|
|
426
|
-
payWithDeep: RawTransactionArgument<boolean>,
|
|
363
|
+
orderId: RawTransactionArgument<number | bigint>,
|
|
427
364
|
];
|
|
428
365
|
typeArguments: [string, string];
|
|
429
366
|
}
|
|
430
|
-
/**
|
|
431
|
-
export function
|
|
367
|
+
/** Cancels an order */
|
|
368
|
+
export function cancelOrder(options: CancelOrderOptions) {
|
|
432
369
|
const packageAddress = options.package ?? '@deepbook/margin';
|
|
433
|
-
const argumentsTypes = [
|
|
434
|
-
|
|
435
|
-
null
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
null,
|
|
439
|
-
null,
|
|
440
|
-
null,
|
|
441
|
-
'u64',
|
|
442
|
-
'u8',
|
|
443
|
-
'u64',
|
|
444
|
-
'bool',
|
|
445
|
-
'bool',
|
|
446
|
-
'0x2::clock::Clock',
|
|
447
|
-
] satisfies (string | null)[];
|
|
448
|
-
const parameterNames = [
|
|
449
|
-
'registry',
|
|
450
|
-
'marginManager',
|
|
451
|
-
'pool',
|
|
452
|
-
'baseMarginPool',
|
|
453
|
-
'quoteMarginPool',
|
|
454
|
-
'baseOracle',
|
|
455
|
-
'quoteOracle',
|
|
456
|
-
'clientOrderId',
|
|
457
|
-
'selfMatchingOption',
|
|
458
|
-
'quantity',
|
|
459
|
-
'isBid',
|
|
460
|
-
'payWithDeep',
|
|
461
|
-
];
|
|
370
|
+
const argumentsTypes = [null, null, null, 'u128', '0x2::clock::Clock'] satisfies (
|
|
371
|
+
| string
|
|
372
|
+
| null
|
|
373
|
+
)[];
|
|
374
|
+
const parameterNames = ['registry', 'marginManager', 'pool', 'orderId'];
|
|
462
375
|
return (tx: Transaction) =>
|
|
463
376
|
tx.moveCall({
|
|
464
377
|
package: packageAddress,
|
|
465
378
|
module: 'pool_proxy',
|
|
466
|
-
function: '
|
|
379
|
+
function: 'cancel_order',
|
|
467
380
|
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
468
381
|
typeArguments: options.typeArguments,
|
|
469
382
|
});
|
|
470
383
|
}
|
|
471
|
-
export interface
|
|
384
|
+
export interface CancelOrdersArguments {
|
|
472
385
|
registry: RawTransactionArgument<string>;
|
|
473
386
|
marginManager: RawTransactionArgument<string>;
|
|
474
387
|
pool: RawTransactionArgument<string>;
|
|
475
|
-
|
|
476
|
-
quoteMarginPool: RawTransactionArgument<string>;
|
|
477
|
-
baseOracle: RawTransactionArgument<string>;
|
|
478
|
-
quoteOracle: RawTransactionArgument<string>;
|
|
479
|
-
clientOrderId: RawTransactionArgument<number | bigint>;
|
|
480
|
-
orderType: RawTransactionArgument<number>;
|
|
481
|
-
selfMatchingOption: RawTransactionArgument<number>;
|
|
482
|
-
price: RawTransactionArgument<number | bigint>;
|
|
483
|
-
quantity: RawTransactionArgument<number | bigint>;
|
|
484
|
-
isBid: RawTransactionArgument<boolean>;
|
|
485
|
-
payWithDeep: RawTransactionArgument<boolean>;
|
|
486
|
-
expireTimestamp: RawTransactionArgument<number | bigint>;
|
|
388
|
+
orderIds: RawTransactionArgument<Array<number | bigint>>;
|
|
487
389
|
}
|
|
488
|
-
export interface
|
|
390
|
+
export interface CancelOrdersOptions {
|
|
489
391
|
package?: string;
|
|
490
392
|
arguments:
|
|
491
|
-
|
|
|
393
|
+
| CancelOrdersArguments
|
|
492
394
|
| [
|
|
493
395
|
registry: RawTransactionArgument<string>,
|
|
494
396
|
marginManager: RawTransactionArgument<string>,
|
|
495
397
|
pool: RawTransactionArgument<string>,
|
|
496
|
-
|
|
497
|
-
quoteMarginPool: RawTransactionArgument<string>,
|
|
498
|
-
baseOracle: RawTransactionArgument<string>,
|
|
499
|
-
quoteOracle: RawTransactionArgument<string>,
|
|
500
|
-
clientOrderId: RawTransactionArgument<number | bigint>,
|
|
501
|
-
orderType: RawTransactionArgument<number>,
|
|
502
|
-
selfMatchingOption: RawTransactionArgument<number>,
|
|
503
|
-
price: RawTransactionArgument<number | bigint>,
|
|
504
|
-
quantity: RawTransactionArgument<number | bigint>,
|
|
505
|
-
isBid: RawTransactionArgument<boolean>,
|
|
506
|
-
payWithDeep: RawTransactionArgument<boolean>,
|
|
507
|
-
expireTimestamp: RawTransactionArgument<number | bigint>,
|
|
398
|
+
orderIds: RawTransactionArgument<Array<number | bigint>>,
|
|
508
399
|
];
|
|
509
400
|
typeArguments: [string, string];
|
|
510
401
|
}
|
|
511
|
-
/**
|
|
512
|
-
export function
|
|
402
|
+
/** Cancel multiple orders within a vector. */
|
|
403
|
+
export function cancelOrders(options: CancelOrdersOptions) {
|
|
513
404
|
const packageAddress = options.package ?? '@deepbook/margin';
|
|
514
|
-
const argumentsTypes = [
|
|
515
|
-
|
|
516
|
-
null
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
null,
|
|
520
|
-
null,
|
|
521
|
-
null,
|
|
522
|
-
'u64',
|
|
523
|
-
'u8',
|
|
524
|
-
'u8',
|
|
525
|
-
'u64',
|
|
526
|
-
'u64',
|
|
527
|
-
'bool',
|
|
528
|
-
'bool',
|
|
529
|
-
'u64',
|
|
530
|
-
'0x2::clock::Clock',
|
|
531
|
-
] satisfies (string | null)[];
|
|
532
|
-
const parameterNames = [
|
|
533
|
-
'registry',
|
|
534
|
-
'marginManager',
|
|
535
|
-
'pool',
|
|
536
|
-
'baseMarginPool',
|
|
537
|
-
'quoteMarginPool',
|
|
538
|
-
'baseOracle',
|
|
539
|
-
'quoteOracle',
|
|
540
|
-
'clientOrderId',
|
|
541
|
-
'orderType',
|
|
542
|
-
'selfMatchingOption',
|
|
543
|
-
'price',
|
|
544
|
-
'quantity',
|
|
545
|
-
'isBid',
|
|
546
|
-
'payWithDeep',
|
|
547
|
-
'expireTimestamp',
|
|
548
|
-
];
|
|
405
|
+
const argumentsTypes = [null, null, null, 'vector<u128>', '0x2::clock::Clock'] satisfies (
|
|
406
|
+
| string
|
|
407
|
+
| null
|
|
408
|
+
)[];
|
|
409
|
+
const parameterNames = ['registry', 'marginManager', 'pool', 'orderIds'];
|
|
549
410
|
return (tx: Transaction) =>
|
|
550
411
|
tx.moveCall({
|
|
551
412
|
package: packageAddress,
|
|
552
413
|
module: 'pool_proxy',
|
|
553
|
-
function: '
|
|
414
|
+
function: 'cancel_orders',
|
|
554
415
|
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
555
416
|
typeArguments: options.typeArguments,
|
|
556
417
|
});
|
|
557
418
|
}
|
|
558
|
-
export interface
|
|
419
|
+
export interface CancelAllOrdersArguments {
|
|
559
420
|
registry: RawTransactionArgument<string>;
|
|
560
421
|
marginManager: RawTransactionArgument<string>;
|
|
561
422
|
pool: RawTransactionArgument<string>;
|
|
562
|
-
baseMarginPool: RawTransactionArgument<string>;
|
|
563
|
-
quoteMarginPool: RawTransactionArgument<string>;
|
|
564
|
-
baseOracle: RawTransactionArgument<string>;
|
|
565
|
-
quoteOracle: RawTransactionArgument<string>;
|
|
566
|
-
clientOrderId: RawTransactionArgument<number | bigint>;
|
|
567
|
-
selfMatchingOption: RawTransactionArgument<number>;
|
|
568
|
-
quantity: RawTransactionArgument<number | bigint>;
|
|
569
|
-
isBid: RawTransactionArgument<boolean>;
|
|
570
|
-
payWithDeep: RawTransactionArgument<boolean>;
|
|
571
423
|
}
|
|
572
|
-
export interface
|
|
424
|
+
export interface CancelAllOrdersOptions {
|
|
573
425
|
package?: string;
|
|
574
426
|
arguments:
|
|
575
|
-
|
|
|
427
|
+
| CancelAllOrdersArguments
|
|
576
428
|
| [
|
|
577
429
|
registry: RawTransactionArgument<string>,
|
|
578
430
|
marginManager: RawTransactionArgument<string>,
|
|
579
431
|
pool: RawTransactionArgument<string>,
|
|
580
|
-
baseMarginPool: RawTransactionArgument<string>,
|
|
581
|
-
quoteMarginPool: RawTransactionArgument<string>,
|
|
582
|
-
baseOracle: RawTransactionArgument<string>,
|
|
583
|
-
quoteOracle: RawTransactionArgument<string>,
|
|
584
|
-
clientOrderId: RawTransactionArgument<number | bigint>,
|
|
585
|
-
selfMatchingOption: RawTransactionArgument<number>,
|
|
586
|
-
quantity: RawTransactionArgument<number | bigint>,
|
|
587
|
-
isBid: RawTransactionArgument<boolean>,
|
|
588
|
-
payWithDeep: RawTransactionArgument<boolean>,
|
|
589
432
|
];
|
|
590
433
|
typeArguments: [string, string];
|
|
591
434
|
}
|
|
592
|
-
/**
|
|
593
|
-
|
|
594
|
-
* disabled.
|
|
595
|
-
*
|
|
596
|
-
* Superseded by `place_reduce_only_market_order_and_repay_loan`. A market (taker)
|
|
597
|
-
* fill always pays the spread, which lowers the oracle-valued `risk_ratio` while
|
|
598
|
-
* the debt is unchanged, so the swap-only monotonic check here rejects essentially
|
|
599
|
-
* every taker fill. The `_and_repay` variant deleverages with the proceeds so the
|
|
600
|
-
* net-state ratio actually improves. Kept callable for existing integrators; its
|
|
601
|
-
* reduce-only _direction_ guard matches the other entries — a bid needs base
|
|
602
|
-
* (short-side) debt, the ask needs quote (long-side) debt and sells up to gross
|
|
603
|
-
* base held — with no size cap.
|
|
604
|
-
*/
|
|
605
|
-
export function placeReduceOnlyMarketOrderV2(options: PlaceReduceOnlyMarketOrderV2Options) {
|
|
435
|
+
/** Cancels all orders for the given account. */
|
|
436
|
+
export function cancelAllOrders(options: CancelAllOrdersOptions) {
|
|
606
437
|
const packageAddress = options.package ?? '@deepbook/margin';
|
|
607
|
-
const argumentsTypes = [
|
|
608
|
-
|
|
609
|
-
null,
|
|
610
|
-
null,
|
|
611
|
-
null,
|
|
612
|
-
null,
|
|
613
|
-
null,
|
|
614
|
-
null,
|
|
615
|
-
'u64',
|
|
616
|
-
'u8',
|
|
617
|
-
'u64',
|
|
618
|
-
'bool',
|
|
619
|
-
'bool',
|
|
620
|
-
'0x2::clock::Clock',
|
|
621
|
-
] satisfies (string | null)[];
|
|
622
|
-
const parameterNames = [
|
|
623
|
-
'registry',
|
|
624
|
-
'marginManager',
|
|
625
|
-
'pool',
|
|
626
|
-
'baseMarginPool',
|
|
627
|
-
'quoteMarginPool',
|
|
628
|
-
'baseOracle',
|
|
629
|
-
'quoteOracle',
|
|
630
|
-
'clientOrderId',
|
|
631
|
-
'selfMatchingOption',
|
|
632
|
-
'quantity',
|
|
633
|
-
'isBid',
|
|
634
|
-
'payWithDeep',
|
|
635
|
-
];
|
|
438
|
+
const argumentsTypes = [null, null, null, '0x2::clock::Clock'] satisfies (string | null)[];
|
|
439
|
+
const parameterNames = ['registry', 'marginManager', 'pool'];
|
|
636
440
|
return (tx: Transaction) =>
|
|
637
441
|
tx.moveCall({
|
|
638
442
|
package: packageAddress,
|
|
639
443
|
module: 'pool_proxy',
|
|
640
|
-
function: '
|
|
444
|
+
function: 'cancel_all_orders',
|
|
641
445
|
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
642
446
|
typeArguments: options.typeArguments,
|
|
643
447
|
});
|
|
644
448
|
}
|
|
645
|
-
export interface
|
|
449
|
+
export interface WithdrawSettledAmountsArguments {
|
|
646
450
|
registry: RawTransactionArgument<string>;
|
|
647
451
|
marginManager: RawTransactionArgument<string>;
|
|
648
452
|
pool: RawTransactionArgument<string>;
|
|
649
|
-
baseMarginPool: RawTransactionArgument<string>;
|
|
650
|
-
quoteMarginPool: RawTransactionArgument<string>;
|
|
651
|
-
baseOracle: RawTransactionArgument<string>;
|
|
652
|
-
quoteOracle: RawTransactionArgument<string>;
|
|
653
|
-
clientOrderId: RawTransactionArgument<number | bigint>;
|
|
654
|
-
selfMatchingOption: RawTransactionArgument<number>;
|
|
655
|
-
quantity: RawTransactionArgument<number | bigint>;
|
|
656
|
-
isBid: RawTransactionArgument<boolean>;
|
|
657
|
-
payWithDeep: RawTransactionArgument<boolean>;
|
|
658
453
|
}
|
|
659
|
-
export interface
|
|
454
|
+
export interface WithdrawSettledAmountsOptions {
|
|
660
455
|
package?: string;
|
|
661
456
|
arguments:
|
|
662
|
-
|
|
|
457
|
+
| WithdrawSettledAmountsArguments
|
|
663
458
|
| [
|
|
664
459
|
registry: RawTransactionArgument<string>,
|
|
665
460
|
marginManager: RawTransactionArgument<string>,
|
|
666
461
|
pool: RawTransactionArgument<string>,
|
|
667
|
-
baseMarginPool: RawTransactionArgument<string>,
|
|
668
|
-
quoteMarginPool: RawTransactionArgument<string>,
|
|
669
|
-
baseOracle: RawTransactionArgument<string>,
|
|
670
|
-
quoteOracle: RawTransactionArgument<string>,
|
|
671
|
-
clientOrderId: RawTransactionArgument<number | bigint>,
|
|
672
|
-
selfMatchingOption: RawTransactionArgument<number>,
|
|
673
|
-
quantity: RawTransactionArgument<number | bigint>,
|
|
674
|
-
isBid: RawTransactionArgument<boolean>,
|
|
675
|
-
payWithDeep: RawTransactionArgument<boolean>,
|
|
676
462
|
];
|
|
677
463
|
typeArguments: [string, string];
|
|
678
464
|
}
|
|
679
|
-
/**
|
|
680
|
-
|
|
681
|
-
* repays the loan with the proceeds, then requires the net (post-repay) risk ratio
|
|
682
|
-
* to be at least the pre-trade ratio.
|
|
683
|
-
*
|
|
684
|
-
* The post-repay check is the point. A market close pays the spread, which alone
|
|
685
|
-
* lowers the oracle-valued ratio (debt is unchanged until repay) and would abort
|
|
686
|
-
* the plain reduce-only path. Repaying first deleverages and absorbs the slippage
|
|
687
|
-
* (still bounded by the `assert_price` band), and lets a manager in the
|
|
688
|
-
* `liquidation..min_borrow` band climb out — it cannot reach the borrow floor in a
|
|
689
|
-
* single swap.
|
|
690
|
-
*/
|
|
691
|
-
export function placeReduceOnlyMarketOrderAndRepayLoan(
|
|
692
|
-
options: PlaceReduceOnlyMarketOrderAndRepayLoanOptions,
|
|
693
|
-
) {
|
|
465
|
+
/** Withdraw settled amounts to balance_manager. */
|
|
466
|
+
export function withdrawSettledAmounts(options: WithdrawSettledAmountsOptions) {
|
|
694
467
|
const packageAddress = options.package ?? '@deepbook/margin';
|
|
695
|
-
const argumentsTypes = [
|
|
696
|
-
|
|
697
|
-
null,
|
|
698
|
-
null,
|
|
699
|
-
null,
|
|
700
|
-
null,
|
|
701
|
-
null,
|
|
702
|
-
null,
|
|
703
|
-
'u64',
|
|
704
|
-
'u8',
|
|
705
|
-
'u64',
|
|
706
|
-
'bool',
|
|
707
|
-
'bool',
|
|
708
|
-
'0x2::clock::Clock',
|
|
709
|
-
] satisfies (string | null)[];
|
|
710
|
-
const parameterNames = [
|
|
711
|
-
'registry',
|
|
712
|
-
'marginManager',
|
|
713
|
-
'pool',
|
|
714
|
-
'baseMarginPool',
|
|
715
|
-
'quoteMarginPool',
|
|
716
|
-
'baseOracle',
|
|
717
|
-
'quoteOracle',
|
|
718
|
-
'clientOrderId',
|
|
719
|
-
'selfMatchingOption',
|
|
720
|
-
'quantity',
|
|
721
|
-
'isBid',
|
|
722
|
-
'payWithDeep',
|
|
723
|
-
];
|
|
468
|
+
const argumentsTypes = [null, null, null] satisfies (string | null)[];
|
|
469
|
+
const parameterNames = ['registry', 'marginManager', 'pool'];
|
|
724
470
|
return (tx: Transaction) =>
|
|
725
471
|
tx.moveCall({
|
|
726
472
|
package: packageAddress,
|
|
727
473
|
module: 'pool_proxy',
|
|
728
|
-
function: '
|
|
474
|
+
function: 'withdraw_settled_amounts',
|
|
729
475
|
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
730
476
|
typeArguments: options.typeArguments,
|
|
731
477
|
});
|
|
732
478
|
}
|
|
733
|
-
export interface
|
|
479
|
+
export interface WithdrawSettledAmountsPermissionlessArguments {
|
|
734
480
|
registry: RawTransactionArgument<string>;
|
|
735
481
|
marginManager: RawTransactionArgument<string>;
|
|
736
482
|
pool: RawTransactionArgument<string>;
|
|
737
|
-
baseMarginPool: RawTransactionArgument<string>;
|
|
738
|
-
quoteMarginPool: RawTransactionArgument<string>;
|
|
739
|
-
baseOracle: RawTransactionArgument<string>;
|
|
740
|
-
quoteOracle: RawTransactionArgument<string>;
|
|
741
|
-
clientOrderId: RawTransactionArgument<number | bigint>;
|
|
742
|
-
orderType: RawTransactionArgument<number>;
|
|
743
|
-
selfMatchingOption: RawTransactionArgument<number>;
|
|
744
|
-
price: RawTransactionArgument<number | bigint>;
|
|
745
|
-
quantity: RawTransactionArgument<number | bigint>;
|
|
746
|
-
isBid: RawTransactionArgument<boolean>;
|
|
747
|
-
payWithDeep: RawTransactionArgument<boolean>;
|
|
748
|
-
expireTimestamp: RawTransactionArgument<number | bigint>;
|
|
749
483
|
}
|
|
750
|
-
export interface
|
|
484
|
+
export interface WithdrawSettledAmountsPermissionlessOptions {
|
|
751
485
|
package?: string;
|
|
752
486
|
arguments:
|
|
753
|
-
|
|
|
487
|
+
| WithdrawSettledAmountsPermissionlessArguments
|
|
754
488
|
| [
|
|
755
489
|
registry: RawTransactionArgument<string>,
|
|
756
490
|
marginManager: RawTransactionArgument<string>,
|
|
757
491
|
pool: RawTransactionArgument<string>,
|
|
758
|
-
baseMarginPool: RawTransactionArgument<string>,
|
|
759
|
-
quoteMarginPool: RawTransactionArgument<string>,
|
|
760
|
-
baseOracle: RawTransactionArgument<string>,
|
|
761
|
-
quoteOracle: RawTransactionArgument<string>,
|
|
762
|
-
clientOrderId: RawTransactionArgument<number | bigint>,
|
|
763
|
-
orderType: RawTransactionArgument<number>,
|
|
764
|
-
selfMatchingOption: RawTransactionArgument<number>,
|
|
765
|
-
price: RawTransactionArgument<number | bigint>,
|
|
766
|
-
quantity: RawTransactionArgument<number | bigint>,
|
|
767
|
-
isBid: RawTransactionArgument<boolean>,
|
|
768
|
-
payWithDeep: RawTransactionArgument<boolean>,
|
|
769
|
-
expireTimestamp: RawTransactionArgument<number | bigint>,
|
|
770
492
|
];
|
|
771
493
|
typeArguments: [string, string];
|
|
772
494
|
}
|
|
773
495
|
/**
|
|
774
|
-
*
|
|
775
|
-
*
|
|
776
|
-
* plus the repay-then-net-monotonic gate of
|
|
777
|
-
* `place_reduce_only_market_order_and_repay_loan`: the portion that crosses the
|
|
778
|
-
* book fills immediately and settles, the rest rests as a maker, then the settled
|
|
779
|
-
* (taker) proceeds repay the debt before the monotonic check on the net
|
|
780
|
-
* (post-repay) state.
|
|
781
|
-
*
|
|
782
|
-
* This is the danger-band tool for a _price-bounded_ reduce: a crossing
|
|
783
|
-
* reduce-only limit pays the spread on its taker fills, which alone would abort
|
|
784
|
-
* `place_reduce_only_limit_order_v2`'s swap-only monotonic check; repaying first
|
|
785
|
-
* deleverages so the net ratio holds. The resting remainder only locks balance
|
|
786
|
-
* (counted in assets), so it doesn't move the ratio. Unfilled-and-resting behaves
|
|
787
|
-
* exactly like `place_reduce_only_limit_order_v2` (nothing to repay).
|
|
496
|
+
* Withdraw settled amounts to balance_manager permissionlessly. Anyone can call
|
|
497
|
+
* this function to settle balances for a margin manager.
|
|
788
498
|
*/
|
|
789
|
-
export function
|
|
790
|
-
options:
|
|
499
|
+
export function withdrawSettledAmountsPermissionless(
|
|
500
|
+
options: WithdrawSettledAmountsPermissionlessOptions,
|
|
791
501
|
) {
|
|
792
502
|
const packageAddress = options.package ?? '@deepbook/margin';
|
|
793
|
-
const argumentsTypes = [
|
|
794
|
-
|
|
795
|
-
null,
|
|
796
|
-
null,
|
|
797
|
-
null,
|
|
798
|
-
null,
|
|
799
|
-
null,
|
|
800
|
-
null,
|
|
801
|
-
'u64',
|
|
802
|
-
'u8',
|
|
803
|
-
'u8',
|
|
804
|
-
'u64',
|
|
805
|
-
'u64',
|
|
806
|
-
'bool',
|
|
807
|
-
'bool',
|
|
808
|
-
'u64',
|
|
809
|
-
'0x2::clock::Clock',
|
|
810
|
-
] satisfies (string | null)[];
|
|
811
|
-
const parameterNames = [
|
|
812
|
-
'registry',
|
|
813
|
-
'marginManager',
|
|
814
|
-
'pool',
|
|
815
|
-
'baseMarginPool',
|
|
816
|
-
'quoteMarginPool',
|
|
817
|
-
'baseOracle',
|
|
818
|
-
'quoteOracle',
|
|
819
|
-
'clientOrderId',
|
|
820
|
-
'orderType',
|
|
821
|
-
'selfMatchingOption',
|
|
822
|
-
'price',
|
|
823
|
-
'quantity',
|
|
824
|
-
'isBid',
|
|
825
|
-
'payWithDeep',
|
|
826
|
-
'expireTimestamp',
|
|
827
|
-
];
|
|
503
|
+
const argumentsTypes = [null, null, null] satisfies (string | null)[];
|
|
504
|
+
const parameterNames = ['registry', 'marginManager', 'pool'];
|
|
828
505
|
return (tx: Transaction) =>
|
|
829
506
|
tx.moveCall({
|
|
830
507
|
package: packageAddress,
|
|
831
508
|
module: 'pool_proxy',
|
|
832
|
-
function: '
|
|
509
|
+
function: 'withdraw_settled_amounts_permissionless',
|
|
833
510
|
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
834
511
|
typeArguments: options.typeArguments,
|
|
835
512
|
});
|
|
836
513
|
}
|
|
837
|
-
export interface
|
|
514
|
+
export interface StakeArguments {
|
|
838
515
|
registry: RawTransactionArgument<string>;
|
|
839
516
|
marginManager: RawTransactionArgument<string>;
|
|
840
517
|
pool: RawTransactionArgument<string>;
|
|
841
|
-
|
|
842
|
-
quoteMarginPool: RawTransactionArgument<string>;
|
|
843
|
-
baseOracle: RawTransactionArgument<string>;
|
|
844
|
-
quoteOracle: RawTransactionArgument<string>;
|
|
845
|
-
clientOrderId: RawTransactionArgument<number | bigint>;
|
|
846
|
-
selfMatchingOption: RawTransactionArgument<number>;
|
|
847
|
-
quantity: RawTransactionArgument<number | bigint>;
|
|
848
|
-
isBid: RawTransactionArgument<boolean>;
|
|
849
|
-
payWithDeep: RawTransactionArgument<boolean>;
|
|
518
|
+
amount: RawTransactionArgument<number | bigint>;
|
|
850
519
|
}
|
|
851
|
-
export interface
|
|
520
|
+
export interface StakeOptions {
|
|
852
521
|
package?: string;
|
|
853
522
|
arguments:
|
|
854
|
-
|
|
|
523
|
+
| StakeArguments
|
|
855
524
|
| [
|
|
856
525
|
registry: RawTransactionArgument<string>,
|
|
857
526
|
marginManager: RawTransactionArgument<string>,
|
|
858
527
|
pool: RawTransactionArgument<string>,
|
|
859
|
-
|
|
860
|
-
quoteMarginPool: RawTransactionArgument<string>,
|
|
861
|
-
baseOracle: RawTransactionArgument<string>,
|
|
862
|
-
quoteOracle: RawTransactionArgument<string>,
|
|
863
|
-
clientOrderId: RawTransactionArgument<number | bigint>,
|
|
864
|
-
selfMatchingOption: RawTransactionArgument<number>,
|
|
865
|
-
quantity: RawTransactionArgument<number | bigint>,
|
|
866
|
-
isBid: RawTransactionArgument<boolean>,
|
|
867
|
-
payWithDeep: RawTransactionArgument<boolean>,
|
|
528
|
+
amount: RawTransactionArgument<number | bigint>,
|
|
868
529
|
];
|
|
869
530
|
typeArguments: [string, string];
|
|
870
531
|
}
|
|
871
|
-
/**
|
|
872
|
-
|
|
873
|
-
* on a **monotonic** net-state check: if any debt remains after the repay, the
|
|
874
|
-
* post-repay `risk_ratio` must be at least the pre-trade ratio (improve-or-hold).
|
|
875
|
-
* A full close drives debt to 0 (`risk_ratio` MAX), which always passes.
|
|
876
|
-
*
|
|
877
|
-
* This is the everyday close / deleverage tool. The monotonic gate — rather than
|
|
878
|
-
* the `min_open` opening floor used by `place_market_order_v2` — lets a position
|
|
879
|
-
* in the `liquidation..min_borrow` danger band wind down _partially_: a small
|
|
880
|
-
* close that lifts the ratio from, say, 1.12 to 1.15 is allowed even though 1.15
|
|
881
|
-
* is still below `min_open`, which the opening floor would reject.
|
|
882
|
-
*
|
|
883
|
-
* Not reduce-only and uncapped, but the monotonic check makes a quantity cap
|
|
884
|
-
* unnecessary: a market (taker) fill settles immediately, so any genuinely
|
|
885
|
-
* exposure-_increasing_ trade lowers the ratio and aborts here, while any
|
|
886
|
-
* deleveraging trade is allowed at any size — an overshoot past the debt is fine
|
|
887
|
-
* (surplus is the manager's own holding) and `assert_price` still bounds slippage.
|
|
888
|
-
* Requires margin trading enabled; in reduce-only mode use
|
|
889
|
-
* `place_reduce_only_market_order_and_repay_loan`.
|
|
890
|
-
*/
|
|
891
|
-
export function placeMarketOrderAndRepayLoan(options: PlaceMarketOrderAndRepayLoanOptions) {
|
|
532
|
+
/** Stake DEEP tokens to the pool. */
|
|
533
|
+
export function stake(options: StakeOptions) {
|
|
892
534
|
const packageAddress = options.package ?? '@deepbook/margin';
|
|
893
|
-
const argumentsTypes = [
|
|
894
|
-
|
|
895
|
-
null,
|
|
896
|
-
null,
|
|
897
|
-
null,
|
|
898
|
-
null,
|
|
899
|
-
null,
|
|
900
|
-
null,
|
|
901
|
-
'u64',
|
|
902
|
-
'u8',
|
|
903
|
-
'u64',
|
|
904
|
-
'bool',
|
|
905
|
-
'bool',
|
|
906
|
-
'0x2::clock::Clock',
|
|
907
|
-
] satisfies (string | null)[];
|
|
908
|
-
const parameterNames = [
|
|
909
|
-
'registry',
|
|
910
|
-
'marginManager',
|
|
911
|
-
'pool',
|
|
912
|
-
'baseMarginPool',
|
|
913
|
-
'quoteMarginPool',
|
|
914
|
-
'baseOracle',
|
|
915
|
-
'quoteOracle',
|
|
916
|
-
'clientOrderId',
|
|
917
|
-
'selfMatchingOption',
|
|
918
|
-
'quantity',
|
|
919
|
-
'isBid',
|
|
920
|
-
'payWithDeep',
|
|
921
|
-
];
|
|
535
|
+
const argumentsTypes = [null, null, null, 'u64'] satisfies (string | null)[];
|
|
536
|
+
const parameterNames = ['registry', 'marginManager', 'pool', 'amount'];
|
|
922
537
|
return (tx: Transaction) =>
|
|
923
538
|
tx.moveCall({
|
|
924
539
|
package: packageAddress,
|
|
925
540
|
module: 'pool_proxy',
|
|
926
|
-
function: '
|
|
541
|
+
function: 'stake',
|
|
927
542
|
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
928
543
|
typeArguments: options.typeArguments,
|
|
929
544
|
});
|
|
930
545
|
}
|
|
931
|
-
export interface
|
|
546
|
+
export interface UnstakeArguments {
|
|
932
547
|
registry: RawTransactionArgument<string>;
|
|
933
548
|
marginManager: RawTransactionArgument<string>;
|
|
934
549
|
pool: RawTransactionArgument<string>;
|
|
935
|
-
orderId: RawTransactionArgument<number | bigint>;
|
|
936
|
-
newQuantity: RawTransactionArgument<number | bigint>;
|
|
937
550
|
}
|
|
938
|
-
export interface
|
|
551
|
+
export interface UnstakeOptions {
|
|
939
552
|
package?: string;
|
|
940
553
|
arguments:
|
|
941
|
-
|
|
|
554
|
+
| UnstakeArguments
|
|
942
555
|
| [
|
|
943
556
|
registry: RawTransactionArgument<string>,
|
|
944
557
|
marginManager: RawTransactionArgument<string>,
|
|
945
558
|
pool: RawTransactionArgument<string>,
|
|
946
|
-
orderId: RawTransactionArgument<number | bigint>,
|
|
947
|
-
newQuantity: RawTransactionArgument<number | bigint>,
|
|
948
559
|
];
|
|
949
560
|
typeArguments: [string, string];
|
|
950
561
|
}
|
|
951
|
-
/**
|
|
952
|
-
export function
|
|
562
|
+
/** Unstake DEEP tokens from the pool. */
|
|
563
|
+
export function unstake(options: UnstakeOptions) {
|
|
953
564
|
const packageAddress = options.package ?? '@deepbook/margin';
|
|
954
|
-
const argumentsTypes = [null, null, null
|
|
955
|
-
|
|
956
|
-
| null
|
|
957
|
-
)[];
|
|
958
|
-
const parameterNames = ['registry', 'marginManager', 'pool', 'orderId', 'newQuantity'];
|
|
565
|
+
const argumentsTypes = [null, null, null] satisfies (string | null)[];
|
|
566
|
+
const parameterNames = ['registry', 'marginManager', 'pool'];
|
|
959
567
|
return (tx: Transaction) =>
|
|
960
568
|
tx.moveCall({
|
|
961
569
|
package: packageAddress,
|
|
962
570
|
module: 'pool_proxy',
|
|
963
|
-
function: '
|
|
571
|
+
function: 'unstake',
|
|
964
572
|
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
965
573
|
typeArguments: options.typeArguments,
|
|
966
574
|
});
|
|
967
575
|
}
|
|
968
|
-
export interface
|
|
576
|
+
export interface SubmitProposalArguments {
|
|
969
577
|
registry: RawTransactionArgument<string>;
|
|
970
578
|
marginManager: RawTransactionArgument<string>;
|
|
971
579
|
pool: RawTransactionArgument<string>;
|
|
972
|
-
|
|
580
|
+
takerFee: RawTransactionArgument<number | bigint>;
|
|
581
|
+
makerFee: RawTransactionArgument<number | bigint>;
|
|
582
|
+
stakeRequired: RawTransactionArgument<number | bigint>;
|
|
973
583
|
}
|
|
974
|
-
export interface
|
|
584
|
+
export interface SubmitProposalOptions {
|
|
975
585
|
package?: string;
|
|
976
586
|
arguments:
|
|
977
|
-
|
|
|
587
|
+
| SubmitProposalArguments
|
|
978
588
|
| [
|
|
979
589
|
registry: RawTransactionArgument<string>,
|
|
980
590
|
marginManager: RawTransactionArgument<string>,
|
|
981
591
|
pool: RawTransactionArgument<string>,
|
|
982
|
-
|
|
592
|
+
takerFee: RawTransactionArgument<number | bigint>,
|
|
593
|
+
makerFee: RawTransactionArgument<number | bigint>,
|
|
594
|
+
stakeRequired: RawTransactionArgument<number | bigint>,
|
|
983
595
|
];
|
|
984
596
|
typeArguments: [string, string];
|
|
985
597
|
}
|
|
986
|
-
/**
|
|
987
|
-
export function
|
|
598
|
+
/** Submit proposal using the margin manager. */
|
|
599
|
+
export function submitProposal(options: SubmitProposalOptions) {
|
|
988
600
|
const packageAddress = options.package ?? '@deepbook/margin';
|
|
989
|
-
const argumentsTypes = [null, null, null, '
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
601
|
+
const argumentsTypes = [null, null, null, 'u64', 'u64', 'u64'] satisfies (string | null)[];
|
|
602
|
+
const parameterNames = [
|
|
603
|
+
'registry',
|
|
604
|
+
'marginManager',
|
|
605
|
+
'pool',
|
|
606
|
+
'takerFee',
|
|
607
|
+
'makerFee',
|
|
608
|
+
'stakeRequired',
|
|
609
|
+
];
|
|
994
610
|
return (tx: Transaction) =>
|
|
995
611
|
tx.moveCall({
|
|
996
612
|
package: packageAddress,
|
|
997
613
|
module: 'pool_proxy',
|
|
998
|
-
function: '
|
|
614
|
+
function: 'submit_proposal',
|
|
999
615
|
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
1000
616
|
typeArguments: options.typeArguments,
|
|
1001
617
|
});
|
|
1002
618
|
}
|
|
1003
|
-
export interface
|
|
619
|
+
export interface VoteArguments {
|
|
1004
620
|
registry: RawTransactionArgument<string>;
|
|
1005
621
|
marginManager: RawTransactionArgument<string>;
|
|
1006
622
|
pool: RawTransactionArgument<string>;
|
|
1007
|
-
|
|
623
|
+
proposalId: RawTransactionArgument<string>;
|
|
1008
624
|
}
|
|
1009
|
-
export interface
|
|
625
|
+
export interface VoteOptions {
|
|
1010
626
|
package?: string;
|
|
1011
627
|
arguments:
|
|
1012
|
-
|
|
|
628
|
+
| VoteArguments
|
|
1013
629
|
| [
|
|
1014
630
|
registry: RawTransactionArgument<string>,
|
|
1015
631
|
marginManager: RawTransactionArgument<string>,
|
|
1016
632
|
pool: RawTransactionArgument<string>,
|
|
1017
|
-
|
|
633
|
+
proposalId: RawTransactionArgument<string>,
|
|
1018
634
|
];
|
|
1019
635
|
typeArguments: [string, string];
|
|
1020
636
|
}
|
|
1021
|
-
/**
|
|
1022
|
-
export function
|
|
637
|
+
/** Vote on a proposal using the margin manager. */
|
|
638
|
+
export function vote(options: VoteOptions) {
|
|
1023
639
|
const packageAddress = options.package ?? '@deepbook/margin';
|
|
1024
|
-
const argumentsTypes = [null, null, null, '
|
|
1025
|
-
|
|
1026
|
-
| null
|
|
1027
|
-
)[];
|
|
1028
|
-
const parameterNames = ['registry', 'marginManager', 'pool', 'orderIds'];
|
|
640
|
+
const argumentsTypes = [null, null, null, '0x2::object::ID'] satisfies (string | null)[];
|
|
641
|
+
const parameterNames = ['registry', 'marginManager', 'pool', 'proposalId'];
|
|
1029
642
|
return (tx: Transaction) =>
|
|
1030
643
|
tx.moveCall({
|
|
1031
644
|
package: packageAddress,
|
|
1032
645
|
module: 'pool_proxy',
|
|
1033
|
-
function: '
|
|
646
|
+
function: 'vote',
|
|
1034
647
|
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
1035
648
|
typeArguments: options.typeArguments,
|
|
1036
649
|
});
|
|
1037
650
|
}
|
|
1038
|
-
export interface
|
|
651
|
+
export interface ClaimRebatesArguments {
|
|
1039
652
|
registry: RawTransactionArgument<string>;
|
|
1040
653
|
marginManager: RawTransactionArgument<string>;
|
|
1041
654
|
pool: RawTransactionArgument<string>;
|
|
1042
655
|
}
|
|
1043
|
-
export interface
|
|
656
|
+
export interface ClaimRebatesOptions {
|
|
1044
657
|
package?: string;
|
|
1045
658
|
arguments:
|
|
1046
|
-
|
|
|
659
|
+
| ClaimRebatesArguments
|
|
1047
660
|
| [
|
|
1048
661
|
registry: RawTransactionArgument<string>,
|
|
1049
662
|
marginManager: RawTransactionArgument<string>,
|
|
@@ -1051,247 +664,650 @@ export interface CancelAllOrdersOptions {
|
|
|
1051
664
|
];
|
|
1052
665
|
typeArguments: [string, string];
|
|
1053
666
|
}
|
|
1054
|
-
|
|
1055
|
-
export function cancelAllOrders(options: CancelAllOrdersOptions) {
|
|
667
|
+
export function claimRebates(options: ClaimRebatesOptions) {
|
|
1056
668
|
const packageAddress = options.package ?? '@deepbook/margin';
|
|
1057
|
-
const argumentsTypes = [null, null, null
|
|
669
|
+
const argumentsTypes = [null, null, null] satisfies (string | null)[];
|
|
1058
670
|
const parameterNames = ['registry', 'marginManager', 'pool'];
|
|
1059
671
|
return (tx: Transaction) =>
|
|
1060
672
|
tx.moveCall({
|
|
1061
673
|
package: packageAddress,
|
|
1062
674
|
module: 'pool_proxy',
|
|
1063
|
-
function: '
|
|
675
|
+
function: 'claim_rebates',
|
|
1064
676
|
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
1065
677
|
typeArguments: options.typeArguments,
|
|
1066
678
|
});
|
|
1067
679
|
}
|
|
1068
|
-
export interface
|
|
680
|
+
export interface PlaceLimitOrderV2Arguments {
|
|
1069
681
|
registry: RawTransactionArgument<string>;
|
|
1070
682
|
marginManager: RawTransactionArgument<string>;
|
|
1071
683
|
pool: RawTransactionArgument<string>;
|
|
684
|
+
baseMarginPool: RawTransactionArgument<string>;
|
|
685
|
+
quoteMarginPool: RawTransactionArgument<string>;
|
|
686
|
+
baseOracle: RawTransactionArgument<string>;
|
|
687
|
+
quoteOracle: RawTransactionArgument<string>;
|
|
688
|
+
clientOrderId: RawTransactionArgument<number | bigint>;
|
|
689
|
+
orderType: RawTransactionArgument<number>;
|
|
690
|
+
selfMatchingOption: RawTransactionArgument<number>;
|
|
691
|
+
price: RawTransactionArgument<number | bigint>;
|
|
692
|
+
quantity: RawTransactionArgument<number | bigint>;
|
|
693
|
+
isBid: RawTransactionArgument<boolean>;
|
|
694
|
+
payWithDeep: RawTransactionArgument<boolean>;
|
|
695
|
+
expireTimestamp: RawTransactionArgument<number | bigint>;
|
|
1072
696
|
}
|
|
1073
|
-
export interface
|
|
697
|
+
export interface PlaceLimitOrderV2Options {
|
|
1074
698
|
package?: string;
|
|
1075
699
|
arguments:
|
|
1076
|
-
|
|
|
700
|
+
| PlaceLimitOrderV2Arguments
|
|
1077
701
|
| [
|
|
1078
702
|
registry: RawTransactionArgument<string>,
|
|
1079
703
|
marginManager: RawTransactionArgument<string>,
|
|
1080
704
|
pool: RawTransactionArgument<string>,
|
|
705
|
+
baseMarginPool: RawTransactionArgument<string>,
|
|
706
|
+
quoteMarginPool: RawTransactionArgument<string>,
|
|
707
|
+
baseOracle: RawTransactionArgument<string>,
|
|
708
|
+
quoteOracle: RawTransactionArgument<string>,
|
|
709
|
+
clientOrderId: RawTransactionArgument<number | bigint>,
|
|
710
|
+
orderType: RawTransactionArgument<number>,
|
|
711
|
+
selfMatchingOption: RawTransactionArgument<number>,
|
|
712
|
+
price: RawTransactionArgument<number | bigint>,
|
|
713
|
+
quantity: RawTransactionArgument<number | bigint>,
|
|
714
|
+
isBid: RawTransactionArgument<boolean>,
|
|
715
|
+
payWithDeep: RawTransactionArgument<boolean>,
|
|
716
|
+
expireTimestamp: RawTransactionArgument<number | bigint>,
|
|
1081
717
|
];
|
|
1082
718
|
typeArguments: [string, string];
|
|
1083
719
|
}
|
|
1084
|
-
/**
|
|
1085
|
-
|
|
720
|
+
/**
|
|
721
|
+
* Places a limit order in the pool. Twin:
|
|
722
|
+
* `pool_proxy_upgraded::place_limit_order_v2`. Edit both.
|
|
723
|
+
*/
|
|
724
|
+
export function placeLimitOrderV2(options: PlaceLimitOrderV2Options) {
|
|
1086
725
|
const packageAddress = options.package ?? '@deepbook/margin';
|
|
1087
|
-
const argumentsTypes = [
|
|
1088
|
-
|
|
726
|
+
const argumentsTypes = [
|
|
727
|
+
null,
|
|
728
|
+
null,
|
|
729
|
+
null,
|
|
730
|
+
null,
|
|
731
|
+
null,
|
|
732
|
+
null,
|
|
733
|
+
null,
|
|
734
|
+
'u64',
|
|
735
|
+
'u8',
|
|
736
|
+
'u8',
|
|
737
|
+
'u64',
|
|
738
|
+
'u64',
|
|
739
|
+
'bool',
|
|
740
|
+
'bool',
|
|
741
|
+
'u64',
|
|
742
|
+
'0x2::clock::Clock',
|
|
743
|
+
] satisfies (string | null)[];
|
|
744
|
+
const parameterNames = [
|
|
745
|
+
'registry',
|
|
746
|
+
'marginManager',
|
|
747
|
+
'pool',
|
|
748
|
+
'baseMarginPool',
|
|
749
|
+
'quoteMarginPool',
|
|
750
|
+
'baseOracle',
|
|
751
|
+
'quoteOracle',
|
|
752
|
+
'clientOrderId',
|
|
753
|
+
'orderType',
|
|
754
|
+
'selfMatchingOption',
|
|
755
|
+
'price',
|
|
756
|
+
'quantity',
|
|
757
|
+
'isBid',
|
|
758
|
+
'payWithDeep',
|
|
759
|
+
'expireTimestamp',
|
|
760
|
+
];
|
|
1089
761
|
return (tx: Transaction) =>
|
|
1090
762
|
tx.moveCall({
|
|
1091
763
|
package: packageAddress,
|
|
1092
764
|
module: 'pool_proxy',
|
|
1093
|
-
function: '
|
|
765
|
+
function: 'place_limit_order_v2',
|
|
1094
766
|
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
1095
767
|
typeArguments: options.typeArguments,
|
|
1096
768
|
});
|
|
1097
769
|
}
|
|
1098
|
-
export interface
|
|
770
|
+
export interface PlaceMarketOrderV2Arguments {
|
|
1099
771
|
registry: RawTransactionArgument<string>;
|
|
1100
772
|
marginManager: RawTransactionArgument<string>;
|
|
1101
773
|
pool: RawTransactionArgument<string>;
|
|
774
|
+
baseMarginPool: RawTransactionArgument<string>;
|
|
775
|
+
quoteMarginPool: RawTransactionArgument<string>;
|
|
776
|
+
baseOracle: RawTransactionArgument<string>;
|
|
777
|
+
quoteOracle: RawTransactionArgument<string>;
|
|
778
|
+
clientOrderId: RawTransactionArgument<number | bigint>;
|
|
779
|
+
selfMatchingOption: RawTransactionArgument<number>;
|
|
780
|
+
quantity: RawTransactionArgument<number | bigint>;
|
|
781
|
+
isBid: RawTransactionArgument<boolean>;
|
|
782
|
+
payWithDeep: RawTransactionArgument<boolean>;
|
|
1102
783
|
}
|
|
1103
|
-
export interface
|
|
784
|
+
export interface PlaceMarketOrderV2Options {
|
|
1104
785
|
package?: string;
|
|
1105
786
|
arguments:
|
|
1106
|
-
|
|
|
787
|
+
| PlaceMarketOrderV2Arguments
|
|
1107
788
|
| [
|
|
1108
789
|
registry: RawTransactionArgument<string>,
|
|
1109
790
|
marginManager: RawTransactionArgument<string>,
|
|
1110
791
|
pool: RawTransactionArgument<string>,
|
|
792
|
+
baseMarginPool: RawTransactionArgument<string>,
|
|
793
|
+
quoteMarginPool: RawTransactionArgument<string>,
|
|
794
|
+
baseOracle: RawTransactionArgument<string>,
|
|
795
|
+
quoteOracle: RawTransactionArgument<string>,
|
|
796
|
+
clientOrderId: RawTransactionArgument<number | bigint>,
|
|
797
|
+
selfMatchingOption: RawTransactionArgument<number>,
|
|
798
|
+
quantity: RawTransactionArgument<number | bigint>,
|
|
799
|
+
isBid: RawTransactionArgument<boolean>,
|
|
800
|
+
payWithDeep: RawTransactionArgument<boolean>,
|
|
1111
801
|
];
|
|
1112
802
|
typeArguments: [string, string];
|
|
1113
803
|
}
|
|
1114
804
|
/**
|
|
1115
|
-
*
|
|
1116
|
-
*
|
|
805
|
+
* Places a market order in the pool. Twin:
|
|
806
|
+
* `pool_proxy_upgraded::place_market_order_v2`. Edit both.
|
|
1117
807
|
*/
|
|
1118
|
-
export function
|
|
1119
|
-
options: WithdrawSettledAmountsPermissionlessOptions,
|
|
1120
|
-
) {
|
|
808
|
+
export function placeMarketOrderV2(options: PlaceMarketOrderV2Options) {
|
|
1121
809
|
const packageAddress = options.package ?? '@deepbook/margin';
|
|
1122
|
-
const argumentsTypes = [
|
|
1123
|
-
|
|
810
|
+
const argumentsTypes = [
|
|
811
|
+
null,
|
|
812
|
+
null,
|
|
813
|
+
null,
|
|
814
|
+
null,
|
|
815
|
+
null,
|
|
816
|
+
null,
|
|
817
|
+
null,
|
|
818
|
+
'u64',
|
|
819
|
+
'u8',
|
|
820
|
+
'u64',
|
|
821
|
+
'bool',
|
|
822
|
+
'bool',
|
|
823
|
+
'0x2::clock::Clock',
|
|
824
|
+
] satisfies (string | null)[];
|
|
825
|
+
const parameterNames = [
|
|
826
|
+
'registry',
|
|
827
|
+
'marginManager',
|
|
828
|
+
'pool',
|
|
829
|
+
'baseMarginPool',
|
|
830
|
+
'quoteMarginPool',
|
|
831
|
+
'baseOracle',
|
|
832
|
+
'quoteOracle',
|
|
833
|
+
'clientOrderId',
|
|
834
|
+
'selfMatchingOption',
|
|
835
|
+
'quantity',
|
|
836
|
+
'isBid',
|
|
837
|
+
'payWithDeep',
|
|
838
|
+
];
|
|
1124
839
|
return (tx: Transaction) =>
|
|
1125
840
|
tx.moveCall({
|
|
1126
841
|
package: packageAddress,
|
|
1127
842
|
module: 'pool_proxy',
|
|
1128
|
-
function: '
|
|
843
|
+
function: 'place_market_order_v2',
|
|
1129
844
|
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
1130
845
|
typeArguments: options.typeArguments,
|
|
1131
846
|
});
|
|
1132
847
|
}
|
|
1133
|
-
export interface
|
|
848
|
+
export interface PlaceReduceOnlyLimitOrderV2Arguments {
|
|
1134
849
|
registry: RawTransactionArgument<string>;
|
|
1135
850
|
marginManager: RawTransactionArgument<string>;
|
|
1136
851
|
pool: RawTransactionArgument<string>;
|
|
1137
|
-
|
|
852
|
+
baseMarginPool: RawTransactionArgument<string>;
|
|
853
|
+
quoteMarginPool: RawTransactionArgument<string>;
|
|
854
|
+
baseOracle: RawTransactionArgument<string>;
|
|
855
|
+
quoteOracle: RawTransactionArgument<string>;
|
|
856
|
+
clientOrderId: RawTransactionArgument<number | bigint>;
|
|
857
|
+
orderType: RawTransactionArgument<number>;
|
|
858
|
+
selfMatchingOption: RawTransactionArgument<number>;
|
|
859
|
+
price: RawTransactionArgument<number | bigint>;
|
|
860
|
+
quantity: RawTransactionArgument<number | bigint>;
|
|
861
|
+
isBid: RawTransactionArgument<boolean>;
|
|
862
|
+
payWithDeep: RawTransactionArgument<boolean>;
|
|
863
|
+
expireTimestamp: RawTransactionArgument<number | bigint>;
|
|
1138
864
|
}
|
|
1139
|
-
export interface
|
|
865
|
+
export interface PlaceReduceOnlyLimitOrderV2Options {
|
|
1140
866
|
package?: string;
|
|
1141
867
|
arguments:
|
|
1142
|
-
|
|
|
868
|
+
| PlaceReduceOnlyLimitOrderV2Arguments
|
|
1143
869
|
| [
|
|
1144
870
|
registry: RawTransactionArgument<string>,
|
|
1145
871
|
marginManager: RawTransactionArgument<string>,
|
|
1146
872
|
pool: RawTransactionArgument<string>,
|
|
1147
|
-
|
|
873
|
+
baseMarginPool: RawTransactionArgument<string>,
|
|
874
|
+
quoteMarginPool: RawTransactionArgument<string>,
|
|
875
|
+
baseOracle: RawTransactionArgument<string>,
|
|
876
|
+
quoteOracle: RawTransactionArgument<string>,
|
|
877
|
+
clientOrderId: RawTransactionArgument<number | bigint>,
|
|
878
|
+
orderType: RawTransactionArgument<number>,
|
|
879
|
+
selfMatchingOption: RawTransactionArgument<number>,
|
|
880
|
+
price: RawTransactionArgument<number | bigint>,
|
|
881
|
+
quantity: RawTransactionArgument<number | bigint>,
|
|
882
|
+
isBid: RawTransactionArgument<boolean>,
|
|
883
|
+
payWithDeep: RawTransactionArgument<boolean>,
|
|
884
|
+
expireTimestamp: RawTransactionArgument<number | bigint>,
|
|
1148
885
|
];
|
|
1149
886
|
typeArguments: [string, string];
|
|
1150
887
|
}
|
|
1151
|
-
/**
|
|
1152
|
-
|
|
888
|
+
/**
|
|
889
|
+
* Places a reduce-only order in the pool. Used when margin trading is disabled.
|
|
890
|
+
* Twin: `pool_proxy_upgraded::place_reduce_only_limit_order_v2`. Edit both.
|
|
891
|
+
*/
|
|
892
|
+
export function placeReduceOnlyLimitOrderV2(options: PlaceReduceOnlyLimitOrderV2Options) {
|
|
1153
893
|
const packageAddress = options.package ?? '@deepbook/margin';
|
|
1154
|
-
const argumentsTypes = [
|
|
1155
|
-
|
|
894
|
+
const argumentsTypes = [
|
|
895
|
+
null,
|
|
896
|
+
null,
|
|
897
|
+
null,
|
|
898
|
+
null,
|
|
899
|
+
null,
|
|
900
|
+
null,
|
|
901
|
+
null,
|
|
902
|
+
'u64',
|
|
903
|
+
'u8',
|
|
904
|
+
'u8',
|
|
905
|
+
'u64',
|
|
906
|
+
'u64',
|
|
907
|
+
'bool',
|
|
908
|
+
'bool',
|
|
909
|
+
'u64',
|
|
910
|
+
'0x2::clock::Clock',
|
|
911
|
+
] satisfies (string | null)[];
|
|
912
|
+
const parameterNames = [
|
|
913
|
+
'registry',
|
|
914
|
+
'marginManager',
|
|
915
|
+
'pool',
|
|
916
|
+
'baseMarginPool',
|
|
917
|
+
'quoteMarginPool',
|
|
918
|
+
'baseOracle',
|
|
919
|
+
'quoteOracle',
|
|
920
|
+
'clientOrderId',
|
|
921
|
+
'orderType',
|
|
922
|
+
'selfMatchingOption',
|
|
923
|
+
'price',
|
|
924
|
+
'quantity',
|
|
925
|
+
'isBid',
|
|
926
|
+
'payWithDeep',
|
|
927
|
+
'expireTimestamp',
|
|
928
|
+
];
|
|
1156
929
|
return (tx: Transaction) =>
|
|
1157
930
|
tx.moveCall({
|
|
1158
931
|
package: packageAddress,
|
|
1159
932
|
module: 'pool_proxy',
|
|
1160
|
-
function: '
|
|
933
|
+
function: 'place_reduce_only_limit_order_v2',
|
|
1161
934
|
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
1162
935
|
typeArguments: options.typeArguments,
|
|
1163
936
|
});
|
|
1164
937
|
}
|
|
1165
|
-
export interface
|
|
938
|
+
export interface PlaceReduceOnlyMarketOrderV2Arguments {
|
|
1166
939
|
registry: RawTransactionArgument<string>;
|
|
1167
940
|
marginManager: RawTransactionArgument<string>;
|
|
1168
941
|
pool: RawTransactionArgument<string>;
|
|
942
|
+
baseMarginPool: RawTransactionArgument<string>;
|
|
943
|
+
quoteMarginPool: RawTransactionArgument<string>;
|
|
944
|
+
baseOracle: RawTransactionArgument<string>;
|
|
945
|
+
quoteOracle: RawTransactionArgument<string>;
|
|
946
|
+
clientOrderId: RawTransactionArgument<number | bigint>;
|
|
947
|
+
selfMatchingOption: RawTransactionArgument<number>;
|
|
948
|
+
quantity: RawTransactionArgument<number | bigint>;
|
|
949
|
+
isBid: RawTransactionArgument<boolean>;
|
|
950
|
+
payWithDeep: RawTransactionArgument<boolean>;
|
|
1169
951
|
}
|
|
1170
|
-
export interface
|
|
952
|
+
export interface PlaceReduceOnlyMarketOrderV2Options {
|
|
1171
953
|
package?: string;
|
|
1172
954
|
arguments:
|
|
1173
|
-
|
|
|
955
|
+
| PlaceReduceOnlyMarketOrderV2Arguments
|
|
1174
956
|
| [
|
|
1175
957
|
registry: RawTransactionArgument<string>,
|
|
1176
958
|
marginManager: RawTransactionArgument<string>,
|
|
1177
959
|
pool: RawTransactionArgument<string>,
|
|
960
|
+
baseMarginPool: RawTransactionArgument<string>,
|
|
961
|
+
quoteMarginPool: RawTransactionArgument<string>,
|
|
962
|
+
baseOracle: RawTransactionArgument<string>,
|
|
963
|
+
quoteOracle: RawTransactionArgument<string>,
|
|
964
|
+
clientOrderId: RawTransactionArgument<number | bigint>,
|
|
965
|
+
selfMatchingOption: RawTransactionArgument<number>,
|
|
966
|
+
quantity: RawTransactionArgument<number | bigint>,
|
|
967
|
+
isBid: RawTransactionArgument<boolean>,
|
|
968
|
+
payWithDeep: RawTransactionArgument<boolean>,
|
|
1178
969
|
];
|
|
1179
970
|
typeArguments: [string, string];
|
|
1180
971
|
}
|
|
1181
|
-
/**
|
|
1182
|
-
|
|
972
|
+
/**
|
|
973
|
+
* Places a reduce-only market order in the pool. Used when margin trading is
|
|
974
|
+
* disabled.
|
|
975
|
+
*
|
|
976
|
+
* Superseded by `place_reduce_only_market_order_and_repay_loan`. A market (taker)
|
|
977
|
+
* fill always pays the spread, which lowers the oracle-valued `risk_ratio` while
|
|
978
|
+
* the debt is unchanged, so the swap-only monotonic check here rejects essentially
|
|
979
|
+
* every taker fill. The `_and_repay` variant deleverages with the proceeds so the
|
|
980
|
+
* net-state ratio actually improves. Kept callable for existing integrators; its
|
|
981
|
+
* reduce-only _direction_ guard matches the other entries — a bid needs base
|
|
982
|
+
* (short-side) debt, the ask needs quote (long-side) debt and sells up to gross
|
|
983
|
+
* base held — with no size cap. Twin:
|
|
984
|
+
* `pool_proxy_upgraded::place_reduce_only_market_order_v2`. Edit both.
|
|
985
|
+
*/
|
|
986
|
+
export function placeReduceOnlyMarketOrderV2(options: PlaceReduceOnlyMarketOrderV2Options) {
|
|
1183
987
|
const packageAddress = options.package ?? '@deepbook/margin';
|
|
1184
|
-
const argumentsTypes = [
|
|
1185
|
-
|
|
988
|
+
const argumentsTypes = [
|
|
989
|
+
null,
|
|
990
|
+
null,
|
|
991
|
+
null,
|
|
992
|
+
null,
|
|
993
|
+
null,
|
|
994
|
+
null,
|
|
995
|
+
null,
|
|
996
|
+
'u64',
|
|
997
|
+
'u8',
|
|
998
|
+
'u64',
|
|
999
|
+
'bool',
|
|
1000
|
+
'bool',
|
|
1001
|
+
'0x2::clock::Clock',
|
|
1002
|
+
] satisfies (string | null)[];
|
|
1003
|
+
const parameterNames = [
|
|
1004
|
+
'registry',
|
|
1005
|
+
'marginManager',
|
|
1006
|
+
'pool',
|
|
1007
|
+
'baseMarginPool',
|
|
1008
|
+
'quoteMarginPool',
|
|
1009
|
+
'baseOracle',
|
|
1010
|
+
'quoteOracle',
|
|
1011
|
+
'clientOrderId',
|
|
1012
|
+
'selfMatchingOption',
|
|
1013
|
+
'quantity',
|
|
1014
|
+
'isBid',
|
|
1015
|
+
'payWithDeep',
|
|
1016
|
+
];
|
|
1186
1017
|
return (tx: Transaction) =>
|
|
1187
1018
|
tx.moveCall({
|
|
1188
1019
|
package: packageAddress,
|
|
1189
1020
|
module: 'pool_proxy',
|
|
1190
|
-
function: '
|
|
1021
|
+
function: 'place_reduce_only_market_order_v2',
|
|
1191
1022
|
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
1192
1023
|
typeArguments: options.typeArguments,
|
|
1193
1024
|
});
|
|
1194
1025
|
}
|
|
1195
|
-
export interface
|
|
1026
|
+
export interface PlaceReduceOnlyMarketOrderAndRepayLoanArguments {
|
|
1196
1027
|
registry: RawTransactionArgument<string>;
|
|
1197
1028
|
marginManager: RawTransactionArgument<string>;
|
|
1198
1029
|
pool: RawTransactionArgument<string>;
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1030
|
+
baseMarginPool: RawTransactionArgument<string>;
|
|
1031
|
+
quoteMarginPool: RawTransactionArgument<string>;
|
|
1032
|
+
baseOracle: RawTransactionArgument<string>;
|
|
1033
|
+
quoteOracle: RawTransactionArgument<string>;
|
|
1034
|
+
clientOrderId: RawTransactionArgument<number | bigint>;
|
|
1035
|
+
selfMatchingOption: RawTransactionArgument<number>;
|
|
1036
|
+
quantity: RawTransactionArgument<number | bigint>;
|
|
1037
|
+
isBid: RawTransactionArgument<boolean>;
|
|
1038
|
+
payWithDeep: RawTransactionArgument<boolean>;
|
|
1202
1039
|
}
|
|
1203
|
-
export interface
|
|
1040
|
+
export interface PlaceReduceOnlyMarketOrderAndRepayLoanOptions {
|
|
1204
1041
|
package?: string;
|
|
1205
1042
|
arguments:
|
|
1206
|
-
|
|
|
1043
|
+
| PlaceReduceOnlyMarketOrderAndRepayLoanArguments
|
|
1207
1044
|
| [
|
|
1208
1045
|
registry: RawTransactionArgument<string>,
|
|
1209
1046
|
marginManager: RawTransactionArgument<string>,
|
|
1210
1047
|
pool: RawTransactionArgument<string>,
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1048
|
+
baseMarginPool: RawTransactionArgument<string>,
|
|
1049
|
+
quoteMarginPool: RawTransactionArgument<string>,
|
|
1050
|
+
baseOracle: RawTransactionArgument<string>,
|
|
1051
|
+
quoteOracle: RawTransactionArgument<string>,
|
|
1052
|
+
clientOrderId: RawTransactionArgument<number | bigint>,
|
|
1053
|
+
selfMatchingOption: RawTransactionArgument<number>,
|
|
1054
|
+
quantity: RawTransactionArgument<number | bigint>,
|
|
1055
|
+
isBid: RawTransactionArgument<boolean>,
|
|
1056
|
+
payWithDeep: RawTransactionArgument<boolean>,
|
|
1214
1057
|
];
|
|
1215
1058
|
typeArguments: [string, string];
|
|
1216
1059
|
}
|
|
1217
|
-
/**
|
|
1218
|
-
|
|
1060
|
+
/**
|
|
1061
|
+
* Atomically winds down a leveraged position: places a reduce-only market order,
|
|
1062
|
+
* repays the loan with the proceeds, then requires the net (post-repay) risk ratio
|
|
1063
|
+
* to be at least the pre-trade ratio.
|
|
1064
|
+
*
|
|
1065
|
+
* The post-repay check is the point. A market close pays the spread, which alone
|
|
1066
|
+
* lowers the oracle-valued ratio (debt is unchanged until repay) and would abort
|
|
1067
|
+
* the plain reduce-only path. Repaying first deleverages and absorbs the slippage
|
|
1068
|
+
* (still bounded by the `assert_price` band), and lets a manager in the
|
|
1069
|
+
* `liquidation..min_borrow` band climb out — it cannot reach the borrow floor in a
|
|
1070
|
+
* single swap. Twin:
|
|
1071
|
+
* `pool_proxy_upgraded::place_reduce_only_market_order_and_repay_loan`. Edit both.
|
|
1072
|
+
*/
|
|
1073
|
+
export function placeReduceOnlyMarketOrderAndRepayLoan(
|
|
1074
|
+
options: PlaceReduceOnlyMarketOrderAndRepayLoanOptions,
|
|
1075
|
+
) {
|
|
1219
1076
|
const packageAddress = options.package ?? '@deepbook/margin';
|
|
1220
|
-
const argumentsTypes = [
|
|
1077
|
+
const argumentsTypes = [
|
|
1078
|
+
null,
|
|
1079
|
+
null,
|
|
1080
|
+
null,
|
|
1081
|
+
null,
|
|
1082
|
+
null,
|
|
1083
|
+
null,
|
|
1084
|
+
null,
|
|
1085
|
+
'u64',
|
|
1086
|
+
'u8',
|
|
1087
|
+
'u64',
|
|
1088
|
+
'bool',
|
|
1089
|
+
'bool',
|
|
1090
|
+
'0x2::clock::Clock',
|
|
1091
|
+
] satisfies (string | null)[];
|
|
1221
1092
|
const parameterNames = [
|
|
1222
1093
|
'registry',
|
|
1223
1094
|
'marginManager',
|
|
1224
1095
|
'pool',
|
|
1225
|
-
'
|
|
1226
|
-
'
|
|
1227
|
-
'
|
|
1096
|
+
'baseMarginPool',
|
|
1097
|
+
'quoteMarginPool',
|
|
1098
|
+
'baseOracle',
|
|
1099
|
+
'quoteOracle',
|
|
1100
|
+
'clientOrderId',
|
|
1101
|
+
'selfMatchingOption',
|
|
1102
|
+
'quantity',
|
|
1103
|
+
'isBid',
|
|
1104
|
+
'payWithDeep',
|
|
1228
1105
|
];
|
|
1229
1106
|
return (tx: Transaction) =>
|
|
1230
1107
|
tx.moveCall({
|
|
1231
1108
|
package: packageAddress,
|
|
1232
1109
|
module: 'pool_proxy',
|
|
1233
|
-
function: '
|
|
1110
|
+
function: 'place_reduce_only_market_order_and_repay_loan',
|
|
1234
1111
|
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
1235
1112
|
typeArguments: options.typeArguments,
|
|
1236
1113
|
});
|
|
1237
1114
|
}
|
|
1238
|
-
export interface
|
|
1115
|
+
export interface PlaceReduceOnlyLimitOrderAndRepayLoanArguments {
|
|
1239
1116
|
registry: RawTransactionArgument<string>;
|
|
1240
1117
|
marginManager: RawTransactionArgument<string>;
|
|
1241
1118
|
pool: RawTransactionArgument<string>;
|
|
1242
|
-
|
|
1119
|
+
baseMarginPool: RawTransactionArgument<string>;
|
|
1120
|
+
quoteMarginPool: RawTransactionArgument<string>;
|
|
1121
|
+
baseOracle: RawTransactionArgument<string>;
|
|
1122
|
+
quoteOracle: RawTransactionArgument<string>;
|
|
1123
|
+
clientOrderId: RawTransactionArgument<number | bigint>;
|
|
1124
|
+
orderType: RawTransactionArgument<number>;
|
|
1125
|
+
selfMatchingOption: RawTransactionArgument<number>;
|
|
1126
|
+
price: RawTransactionArgument<number | bigint>;
|
|
1127
|
+
quantity: RawTransactionArgument<number | bigint>;
|
|
1128
|
+
isBid: RawTransactionArgument<boolean>;
|
|
1129
|
+
payWithDeep: RawTransactionArgument<boolean>;
|
|
1130
|
+
expireTimestamp: RawTransactionArgument<number | bigint>;
|
|
1243
1131
|
}
|
|
1244
|
-
export interface
|
|
1132
|
+
export interface PlaceReduceOnlyLimitOrderAndRepayLoanOptions {
|
|
1245
1133
|
package?: string;
|
|
1246
1134
|
arguments:
|
|
1247
|
-
|
|
|
1135
|
+
| PlaceReduceOnlyLimitOrderAndRepayLoanArguments
|
|
1248
1136
|
| [
|
|
1249
1137
|
registry: RawTransactionArgument<string>,
|
|
1250
1138
|
marginManager: RawTransactionArgument<string>,
|
|
1251
1139
|
pool: RawTransactionArgument<string>,
|
|
1252
|
-
|
|
1140
|
+
baseMarginPool: RawTransactionArgument<string>,
|
|
1141
|
+
quoteMarginPool: RawTransactionArgument<string>,
|
|
1142
|
+
baseOracle: RawTransactionArgument<string>,
|
|
1143
|
+
quoteOracle: RawTransactionArgument<string>,
|
|
1144
|
+
clientOrderId: RawTransactionArgument<number | bigint>,
|
|
1145
|
+
orderType: RawTransactionArgument<number>,
|
|
1146
|
+
selfMatchingOption: RawTransactionArgument<number>,
|
|
1147
|
+
price: RawTransactionArgument<number | bigint>,
|
|
1148
|
+
quantity: RawTransactionArgument<number | bigint>,
|
|
1149
|
+
isBid: RawTransactionArgument<boolean>,
|
|
1150
|
+
payWithDeep: RawTransactionArgument<boolean>,
|
|
1151
|
+
expireTimestamp: RawTransactionArgument<number | bigint>,
|
|
1253
1152
|
];
|
|
1254
1153
|
typeArguments: [string, string];
|
|
1255
1154
|
}
|
|
1256
|
-
/**
|
|
1257
|
-
|
|
1155
|
+
/**
|
|
1156
|
+
* Reduce-only **limit** order that atomically repays the loan with the taker
|
|
1157
|
+
* fills. It is the limit/maker behaviour of `place_reduce_only_limit_order_v2`
|
|
1158
|
+
* plus the repay-then-net-monotonic gate of
|
|
1159
|
+
* `place_reduce_only_market_order_and_repay_loan`: the portion that crosses the
|
|
1160
|
+
* book fills immediately and settles, the rest rests as a maker, then the settled
|
|
1161
|
+
* (taker) proceeds repay the debt before the monotonic check on the net
|
|
1162
|
+
* (post-repay) state.
|
|
1163
|
+
*
|
|
1164
|
+
* This is the danger-band tool for a _price-bounded_ reduce: a crossing
|
|
1165
|
+
* reduce-only limit pays the spread on its taker fills, which alone would abort
|
|
1166
|
+
* `place_reduce_only_limit_order_v2`'s swap-only monotonic check; repaying first
|
|
1167
|
+
* deleverages so the net ratio holds. The resting remainder only locks balance
|
|
1168
|
+
* (counted in assets), so it doesn't move the ratio. Unfilled-and-resting behaves
|
|
1169
|
+
* exactly like `place_reduce_only_limit_order_v2` (nothing to repay). Twin:
|
|
1170
|
+
* `pool_proxy_upgraded::place_reduce_only_limit_order_and_repay_loan`. Edit both.
|
|
1171
|
+
*/
|
|
1172
|
+
export function placeReduceOnlyLimitOrderAndRepayLoan(
|
|
1173
|
+
options: PlaceReduceOnlyLimitOrderAndRepayLoanOptions,
|
|
1174
|
+
) {
|
|
1258
1175
|
const packageAddress = options.package ?? '@deepbook/margin';
|
|
1259
|
-
const argumentsTypes = [
|
|
1260
|
-
|
|
1176
|
+
const argumentsTypes = [
|
|
1177
|
+
null,
|
|
1178
|
+
null,
|
|
1179
|
+
null,
|
|
1180
|
+
null,
|
|
1181
|
+
null,
|
|
1182
|
+
null,
|
|
1183
|
+
null,
|
|
1184
|
+
'u64',
|
|
1185
|
+
'u8',
|
|
1186
|
+
'u8',
|
|
1187
|
+
'u64',
|
|
1188
|
+
'u64',
|
|
1189
|
+
'bool',
|
|
1190
|
+
'bool',
|
|
1191
|
+
'u64',
|
|
1192
|
+
'0x2::clock::Clock',
|
|
1193
|
+
] satisfies (string | null)[];
|
|
1194
|
+
const parameterNames = [
|
|
1195
|
+
'registry',
|
|
1196
|
+
'marginManager',
|
|
1197
|
+
'pool',
|
|
1198
|
+
'baseMarginPool',
|
|
1199
|
+
'quoteMarginPool',
|
|
1200
|
+
'baseOracle',
|
|
1201
|
+
'quoteOracle',
|
|
1202
|
+
'clientOrderId',
|
|
1203
|
+
'orderType',
|
|
1204
|
+
'selfMatchingOption',
|
|
1205
|
+
'price',
|
|
1206
|
+
'quantity',
|
|
1207
|
+
'isBid',
|
|
1208
|
+
'payWithDeep',
|
|
1209
|
+
'expireTimestamp',
|
|
1210
|
+
];
|
|
1261
1211
|
return (tx: Transaction) =>
|
|
1262
1212
|
tx.moveCall({
|
|
1263
1213
|
package: packageAddress,
|
|
1264
1214
|
module: 'pool_proxy',
|
|
1265
|
-
function: '
|
|
1215
|
+
function: 'place_reduce_only_limit_order_and_repay_loan',
|
|
1266
1216
|
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
1267
1217
|
typeArguments: options.typeArguments,
|
|
1268
1218
|
});
|
|
1269
1219
|
}
|
|
1270
|
-
export interface
|
|
1220
|
+
export interface PlaceMarketOrderAndRepayLoanArguments {
|
|
1271
1221
|
registry: RawTransactionArgument<string>;
|
|
1272
1222
|
marginManager: RawTransactionArgument<string>;
|
|
1273
1223
|
pool: RawTransactionArgument<string>;
|
|
1224
|
+
baseMarginPool: RawTransactionArgument<string>;
|
|
1225
|
+
quoteMarginPool: RawTransactionArgument<string>;
|
|
1226
|
+
baseOracle: RawTransactionArgument<string>;
|
|
1227
|
+
quoteOracle: RawTransactionArgument<string>;
|
|
1228
|
+
clientOrderId: RawTransactionArgument<number | bigint>;
|
|
1229
|
+
selfMatchingOption: RawTransactionArgument<number>;
|
|
1230
|
+
quantity: RawTransactionArgument<number | bigint>;
|
|
1231
|
+
isBid: RawTransactionArgument<boolean>;
|
|
1232
|
+
payWithDeep: RawTransactionArgument<boolean>;
|
|
1274
1233
|
}
|
|
1275
|
-
export interface
|
|
1234
|
+
export interface PlaceMarketOrderAndRepayLoanOptions {
|
|
1276
1235
|
package?: string;
|
|
1277
1236
|
arguments:
|
|
1278
|
-
|
|
|
1237
|
+
| PlaceMarketOrderAndRepayLoanArguments
|
|
1279
1238
|
| [
|
|
1280
1239
|
registry: RawTransactionArgument<string>,
|
|
1281
1240
|
marginManager: RawTransactionArgument<string>,
|
|
1282
1241
|
pool: RawTransactionArgument<string>,
|
|
1242
|
+
baseMarginPool: RawTransactionArgument<string>,
|
|
1243
|
+
quoteMarginPool: RawTransactionArgument<string>,
|
|
1244
|
+
baseOracle: RawTransactionArgument<string>,
|
|
1245
|
+
quoteOracle: RawTransactionArgument<string>,
|
|
1246
|
+
clientOrderId: RawTransactionArgument<number | bigint>,
|
|
1247
|
+
selfMatchingOption: RawTransactionArgument<number>,
|
|
1248
|
+
quantity: RawTransactionArgument<number | bigint>,
|
|
1249
|
+
isBid: RawTransactionArgument<boolean>,
|
|
1250
|
+
payWithDeep: RawTransactionArgument<boolean>,
|
|
1283
1251
|
];
|
|
1284
1252
|
typeArguments: [string, string];
|
|
1285
1253
|
}
|
|
1286
|
-
|
|
1254
|
+
/**
|
|
1255
|
+
* Atomically places a market order and repays the loan with the proceeds, gating
|
|
1256
|
+
* on a **monotonic** net-state check: if any debt remains after the repay, the
|
|
1257
|
+
* post-repay `risk_ratio` must be at least the pre-trade ratio (improve-or-hold).
|
|
1258
|
+
* A full close drives debt to 0 (`risk_ratio` MAX), which always passes.
|
|
1259
|
+
*
|
|
1260
|
+
* This is the everyday close / deleverage tool. The monotonic gate — rather than
|
|
1261
|
+
* the `min_open` opening floor used by `place_market_order_v2` — lets a position
|
|
1262
|
+
* in the `liquidation..min_borrow` danger band wind down _partially_: a small
|
|
1263
|
+
* close that lifts the ratio from, say, 1.12 to 1.15 is allowed even though 1.15
|
|
1264
|
+
* is still below `min_open`, which the opening floor would reject.
|
|
1265
|
+
*
|
|
1266
|
+
* Not reduce-only and uncapped, but the monotonic check makes a quantity cap
|
|
1267
|
+
* unnecessary: a market (taker) fill settles immediately, so any genuinely
|
|
1268
|
+
* exposure-_increasing_ trade lowers the ratio and aborts here, while any
|
|
1269
|
+
* deleveraging trade is allowed at any size — an overshoot past the debt is fine
|
|
1270
|
+
* (surplus is the manager's own holding) and `assert_price` still bounds slippage.
|
|
1271
|
+
* Requires margin trading enabled; in reduce-only mode use
|
|
1272
|
+
* `place_reduce_only_market_order_and_repay_loan`. Twin:
|
|
1273
|
+
* `pool_proxy_upgraded::place_market_order_and_repay_loan`. Edit both.
|
|
1274
|
+
*/
|
|
1275
|
+
export function placeMarketOrderAndRepayLoan(options: PlaceMarketOrderAndRepayLoanOptions) {
|
|
1287
1276
|
const packageAddress = options.package ?? '@deepbook/margin';
|
|
1288
|
-
const argumentsTypes = [
|
|
1289
|
-
|
|
1277
|
+
const argumentsTypes = [
|
|
1278
|
+
null,
|
|
1279
|
+
null,
|
|
1280
|
+
null,
|
|
1281
|
+
null,
|
|
1282
|
+
null,
|
|
1283
|
+
null,
|
|
1284
|
+
null,
|
|
1285
|
+
'u64',
|
|
1286
|
+
'u8',
|
|
1287
|
+
'u64',
|
|
1288
|
+
'bool',
|
|
1289
|
+
'bool',
|
|
1290
|
+
'0x2::clock::Clock',
|
|
1291
|
+
] satisfies (string | null)[];
|
|
1292
|
+
const parameterNames = [
|
|
1293
|
+
'registry',
|
|
1294
|
+
'marginManager',
|
|
1295
|
+
'pool',
|
|
1296
|
+
'baseMarginPool',
|
|
1297
|
+
'quoteMarginPool',
|
|
1298
|
+
'baseOracle',
|
|
1299
|
+
'quoteOracle',
|
|
1300
|
+
'clientOrderId',
|
|
1301
|
+
'selfMatchingOption',
|
|
1302
|
+
'quantity',
|
|
1303
|
+
'isBid',
|
|
1304
|
+
'payWithDeep',
|
|
1305
|
+
];
|
|
1290
1306
|
return (tx: Transaction) =>
|
|
1291
1307
|
tx.moveCall({
|
|
1292
1308
|
package: packageAddress,
|
|
1293
1309
|
module: 'pool_proxy',
|
|
1294
|
-
function: '
|
|
1310
|
+
function: 'place_market_order_and_repay_loan',
|
|
1295
1311
|
arguments: normalizeMoveArguments(options.arguments, argumentsTypes, parameterNames),
|
|
1296
1312
|
typeArguments: options.typeArguments,
|
|
1297
1313
|
});
|