@mysten/deepbook-v3 0.20.2 → 0.20.4
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 +16 -0
- package/dist/cjs/client.d.ts +51 -30
- package/dist/cjs/client.js +110 -43
- package/dist/cjs/client.js.map +2 -2
- package/dist/cjs/transactions/marginAdmin.d.ts +7 -0
- package/dist/cjs/transactions/marginAdmin.js +23 -1
- package/dist/cjs/transactions/marginAdmin.js.map +2 -2
- package/dist/cjs/transactions/marginManager.d.ts +10 -0
- package/dist/cjs/transactions/marginManager.js +30 -0
- package/dist/cjs/transactions/marginManager.js.map +2 -2
- package/dist/cjs/transactions/marginPool.d.ts +1 -1
- package/dist/cjs/transactions/marginPool.js +6 -2
- package/dist/cjs/transactions/marginPool.js.map +2 -2
- package/dist/esm/client.d.ts +51 -30
- package/dist/esm/client.js +110 -43
- package/dist/esm/client.js.map +2 -2
- package/dist/esm/transactions/marginAdmin.d.ts +7 -0
- package/dist/esm/transactions/marginAdmin.js +23 -1
- package/dist/esm/transactions/marginAdmin.js.map +2 -2
- package/dist/esm/transactions/marginManager.d.ts +10 -0
- package/dist/esm/transactions/marginManager.js +30 -0
- package/dist/esm/transactions/marginManager.js.map +2 -2
- package/dist/esm/transactions/marginPool.d.ts +1 -1
- package/dist/esm/transactions/marginPool.js +6 -2
- package/dist/esm/transactions/marginPool.js.map +2 -2
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/client.ts +151 -59
- package/src/transactions/marginAdmin.ts +23 -0
- package/src/transactions/marginManager.ts +31 -0
- package/src/transactions/marginPool.ts +6 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @mysten/deepbook-v3
|
|
2
2
|
|
|
3
|
+
## 0.20.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- bf5773f: Improve read only functions and add manager state function
|
|
8
|
+
- d8355d7: Admin withdraw referral fees
|
|
9
|
+
|
|
10
|
+
## 0.20.3
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- a2f84a3: Update margin withdraw referral function
|
|
15
|
+
- e0490df: Fix deepbook admin function
|
|
16
|
+
- Updated dependencies [88bdbac]
|
|
17
|
+
- @mysten/sui@1.45.0
|
|
18
|
+
|
|
3
19
|
## 0.20.2
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/dist/cjs/client.d.ts
CHANGED
|
@@ -455,71 +455,62 @@ export declare class DeepBookClient {
|
|
|
455
455
|
getUserSupplyAmount(coinKey: string, supplierCapId: string, decimals?: number): Promise<string>;
|
|
456
456
|
/**
|
|
457
457
|
* @description Get the owner address of a margin manager
|
|
458
|
-
* @param {string}
|
|
459
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
458
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
460
459
|
* @returns {Promise<string>} The owner address
|
|
461
460
|
*/
|
|
462
|
-
getMarginManagerOwner(
|
|
461
|
+
getMarginManagerOwner(marginManagerKey: string): Promise<string>;
|
|
463
462
|
/**
|
|
464
463
|
* @description Get the DeepBook pool ID associated with a margin manager
|
|
465
|
-
* @param {string}
|
|
466
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
464
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
467
465
|
* @returns {Promise<string>} The DeepBook pool ID
|
|
468
466
|
*/
|
|
469
|
-
getMarginManagerDeepbookPool(
|
|
467
|
+
getMarginManagerDeepbookPool(marginManagerKey: string): Promise<string>;
|
|
470
468
|
/**
|
|
471
469
|
* @description Get the margin pool ID (if any) associated with a margin manager
|
|
472
|
-
* @param {string}
|
|
473
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
470
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
474
471
|
* @returns {Promise<string | null>} The margin pool ID or null if no active loan
|
|
475
472
|
*/
|
|
476
|
-
getMarginManagerMarginPoolId(
|
|
473
|
+
getMarginManagerMarginPoolId(marginManagerKey: string): Promise<string | null>;
|
|
477
474
|
/**
|
|
478
475
|
* @description Get borrowed shares for both base and quote assets
|
|
479
|
-
* @param {string}
|
|
480
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
476
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
481
477
|
* @returns {Promise<{baseShares: string, quoteShares: string}>} The borrowed shares
|
|
482
478
|
*/
|
|
483
|
-
getMarginManagerBorrowedShares(
|
|
479
|
+
getMarginManagerBorrowedShares(marginManagerKey: string): Promise<{
|
|
484
480
|
baseShares: string;
|
|
485
481
|
quoteShares: string;
|
|
486
482
|
}>;
|
|
487
483
|
/**
|
|
488
484
|
* @description Get borrowed base shares
|
|
489
|
-
* @param {string}
|
|
490
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
485
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
491
486
|
* @returns {Promise<string>} The borrowed base shares
|
|
492
487
|
*/
|
|
493
|
-
getMarginManagerBorrowedBaseShares(
|
|
488
|
+
getMarginManagerBorrowedBaseShares(marginManagerKey: string): Promise<string>;
|
|
494
489
|
/**
|
|
495
490
|
* @description Get borrowed quote shares
|
|
496
|
-
* @param {string}
|
|
497
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
491
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
498
492
|
* @returns {Promise<string>} The borrowed quote shares
|
|
499
493
|
*/
|
|
500
|
-
getMarginManagerBorrowedQuoteShares(
|
|
494
|
+
getMarginManagerBorrowedQuoteShares(marginManagerKey: string): Promise<string>;
|
|
501
495
|
/**
|
|
502
496
|
* @description Check if margin manager has base asset debt
|
|
503
|
-
* @param {string}
|
|
504
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
497
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
505
498
|
* @returns {Promise<boolean>} True if has base debt, false otherwise
|
|
506
499
|
*/
|
|
507
|
-
getMarginManagerHasBaseDebt(
|
|
500
|
+
getMarginManagerHasBaseDebt(marginManagerKey: string): Promise<boolean>;
|
|
508
501
|
/**
|
|
509
502
|
* @description Get the balance manager ID for a margin manager
|
|
510
|
-
* @param {string}
|
|
511
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
503
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
512
504
|
* @returns {Promise<string>} The balance manager ID
|
|
513
505
|
*/
|
|
514
|
-
getMarginManagerBalanceManagerId(
|
|
506
|
+
getMarginManagerBalanceManagerId(marginManagerKey: string): Promise<string>;
|
|
515
507
|
/**
|
|
516
508
|
* @description Calculate assets (base and quote) for a margin manager
|
|
517
|
-
* @param {string}
|
|
518
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
509
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
519
510
|
* @param {number} decimals Number of decimal places to show (default: 6)
|
|
520
511
|
* @returns {Promise<{baseAsset: string, quoteAsset: string}>} The base and quote assets
|
|
521
512
|
*/
|
|
522
|
-
getMarginManagerAssets(
|
|
513
|
+
getMarginManagerAssets(marginManagerKey: string, decimals?: number): Promise<{
|
|
523
514
|
baseAsset: string;
|
|
524
515
|
quoteAsset: string;
|
|
525
516
|
}>;
|
|
@@ -527,14 +518,44 @@ export declare class DeepBookClient {
|
|
|
527
518
|
* @description Calculate debts (base and quote) for a margin manager
|
|
528
519
|
* NOTE: This function automatically determines whether to use base or quote margin pool
|
|
529
520
|
* based on hasBaseDebt. You don't need to specify the debt coin type.
|
|
530
|
-
* @param {string}
|
|
531
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
521
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
532
522
|
* @param {number} decimals Number of decimal places to show (default: 6)
|
|
533
523
|
* @returns {Promise<{baseDebt: string, quoteDebt: string}>} The base and quote debts
|
|
534
524
|
*/
|
|
535
|
-
getMarginManagerDebts(
|
|
525
|
+
getMarginManagerDebts(marginManagerKey: string, decimals?: number): Promise<{
|
|
526
|
+
baseDebt: string;
|
|
527
|
+
quoteDebt: string;
|
|
528
|
+
}>;
|
|
529
|
+
/**
|
|
530
|
+
* @description Get comprehensive state information for a margin manager
|
|
531
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
532
|
+
* @param {number} decimals Number of decimal places to show (default: 6)
|
|
533
|
+
* @returns {Promise<{
|
|
534
|
+
* managerId: string,
|
|
535
|
+
* deepbookPoolId: string,
|
|
536
|
+
* riskRatio: number,
|
|
537
|
+
* baseAsset: string,
|
|
538
|
+
* quoteAsset: string,
|
|
539
|
+
* baseDebt: string,
|
|
540
|
+
* quoteDebt: string,
|
|
541
|
+
* basePythPrice: string,
|
|
542
|
+
* basePythDecimals: number,
|
|
543
|
+
* quotePythPrice: string,
|
|
544
|
+
* quotePythDecimals: number
|
|
545
|
+
* }>} Comprehensive margin manager state
|
|
546
|
+
*/
|
|
547
|
+
getMarginManagerState(marginManagerKey: string, decimals?: number): Promise<{
|
|
548
|
+
managerId: string;
|
|
549
|
+
deepbookPoolId: string;
|
|
550
|
+
riskRatio: number;
|
|
551
|
+
baseAsset: string;
|
|
552
|
+
quoteAsset: string;
|
|
536
553
|
baseDebt: string;
|
|
537
554
|
quoteDebt: string;
|
|
555
|
+
basePythPrice: string;
|
|
556
|
+
basePythDecimals: number;
|
|
557
|
+
quotePythPrice: string;
|
|
558
|
+
quotePythDecimals: number;
|
|
538
559
|
}>;
|
|
539
560
|
/**
|
|
540
561
|
* @description Check if a deepbook pool is enabled for margin trading
|
package/dist/cjs/client.js
CHANGED
|
@@ -958,13 +958,13 @@ class DeepBookClient {
|
|
|
958
958
|
// === Margin Manager Read-Only Functions ===
|
|
959
959
|
/**
|
|
960
960
|
* @description Get the owner address of a margin manager
|
|
961
|
-
* @param {string}
|
|
962
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
961
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
963
962
|
* @returns {Promise<string>} The owner address
|
|
964
963
|
*/
|
|
965
|
-
async getMarginManagerOwner(
|
|
964
|
+
async getMarginManagerOwner(marginManagerKey) {
|
|
965
|
+
const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
|
|
966
966
|
const tx = new import_transactions.Transaction();
|
|
967
|
-
tx.add(this.marginManager.ownerByPoolKey(poolKey,
|
|
967
|
+
tx.add(this.marginManager.ownerByPoolKey(manager.poolKey, manager.address));
|
|
968
968
|
const res = await this.client.devInspectTransactionBlock({
|
|
969
969
|
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
970
970
|
transactionBlock: tx
|
|
@@ -974,13 +974,13 @@ class DeepBookClient {
|
|
|
974
974
|
}
|
|
975
975
|
/**
|
|
976
976
|
* @description Get the DeepBook pool ID associated with a margin manager
|
|
977
|
-
* @param {string}
|
|
978
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
977
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
979
978
|
* @returns {Promise<string>} The DeepBook pool ID
|
|
980
979
|
*/
|
|
981
|
-
async getMarginManagerDeepbookPool(
|
|
980
|
+
async getMarginManagerDeepbookPool(marginManagerKey) {
|
|
981
|
+
const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
|
|
982
982
|
const tx = new import_transactions.Transaction();
|
|
983
|
-
tx.add(this.marginManager.deepbookPool(poolKey,
|
|
983
|
+
tx.add(this.marginManager.deepbookPool(manager.poolKey, manager.address));
|
|
984
984
|
const res = await this.client.devInspectTransactionBlock({
|
|
985
985
|
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
986
986
|
transactionBlock: tx
|
|
@@ -990,13 +990,13 @@ class DeepBookClient {
|
|
|
990
990
|
}
|
|
991
991
|
/**
|
|
992
992
|
* @description Get the margin pool ID (if any) associated with a margin manager
|
|
993
|
-
* @param {string}
|
|
994
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
993
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
995
994
|
* @returns {Promise<string | null>} The margin pool ID or null if no active loan
|
|
996
995
|
*/
|
|
997
|
-
async getMarginManagerMarginPoolId(
|
|
996
|
+
async getMarginManagerMarginPoolId(marginManagerKey) {
|
|
997
|
+
const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
|
|
998
998
|
const tx = new import_transactions.Transaction();
|
|
999
|
-
tx.add(this.marginManager.marginPoolId(poolKey,
|
|
999
|
+
tx.add(this.marginManager.marginPoolId(manager.poolKey, manager.address));
|
|
1000
1000
|
const res = await this.client.devInspectTransactionBlock({
|
|
1001
1001
|
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1002
1002
|
transactionBlock: tx
|
|
@@ -1007,13 +1007,13 @@ class DeepBookClient {
|
|
|
1007
1007
|
}
|
|
1008
1008
|
/**
|
|
1009
1009
|
* @description Get borrowed shares for both base and quote assets
|
|
1010
|
-
* @param {string}
|
|
1011
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
1010
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
1012
1011
|
* @returns {Promise<{baseShares: string, quoteShares: string}>} The borrowed shares
|
|
1013
1012
|
*/
|
|
1014
|
-
async getMarginManagerBorrowedShares(
|
|
1013
|
+
async getMarginManagerBorrowedShares(marginManagerKey) {
|
|
1014
|
+
const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
|
|
1015
1015
|
const tx = new import_transactions.Transaction();
|
|
1016
|
-
tx.add(this.marginManager.borrowedShares(poolKey,
|
|
1016
|
+
tx.add(this.marginManager.borrowedShares(manager.poolKey, manager.address));
|
|
1017
1017
|
const res = await this.client.devInspectTransactionBlock({
|
|
1018
1018
|
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1019
1019
|
transactionBlock: tx
|
|
@@ -1026,13 +1026,13 @@ class DeepBookClient {
|
|
|
1026
1026
|
}
|
|
1027
1027
|
/**
|
|
1028
1028
|
* @description Get borrowed base shares
|
|
1029
|
-
* @param {string}
|
|
1030
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
1029
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
1031
1030
|
* @returns {Promise<string>} The borrowed base shares
|
|
1032
1031
|
*/
|
|
1033
|
-
async getMarginManagerBorrowedBaseShares(
|
|
1032
|
+
async getMarginManagerBorrowedBaseShares(marginManagerKey) {
|
|
1033
|
+
const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
|
|
1034
1034
|
const tx = new import_transactions.Transaction();
|
|
1035
|
-
tx.add(this.marginManager.borrowedBaseShares(poolKey,
|
|
1035
|
+
tx.add(this.marginManager.borrowedBaseShares(manager.poolKey, manager.address));
|
|
1036
1036
|
const res = await this.client.devInspectTransactionBlock({
|
|
1037
1037
|
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1038
1038
|
transactionBlock: tx
|
|
@@ -1042,13 +1042,13 @@ class DeepBookClient {
|
|
|
1042
1042
|
}
|
|
1043
1043
|
/**
|
|
1044
1044
|
* @description Get borrowed quote shares
|
|
1045
|
-
* @param {string}
|
|
1046
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
1045
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
1047
1046
|
* @returns {Promise<string>} The borrowed quote shares
|
|
1048
1047
|
*/
|
|
1049
|
-
async getMarginManagerBorrowedQuoteShares(
|
|
1048
|
+
async getMarginManagerBorrowedQuoteShares(marginManagerKey) {
|
|
1049
|
+
const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
|
|
1050
1050
|
const tx = new import_transactions.Transaction();
|
|
1051
|
-
tx.add(this.marginManager.borrowedQuoteShares(poolKey,
|
|
1051
|
+
tx.add(this.marginManager.borrowedQuoteShares(manager.poolKey, manager.address));
|
|
1052
1052
|
const res = await this.client.devInspectTransactionBlock({
|
|
1053
1053
|
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1054
1054
|
transactionBlock: tx
|
|
@@ -1058,13 +1058,13 @@ class DeepBookClient {
|
|
|
1058
1058
|
}
|
|
1059
1059
|
/**
|
|
1060
1060
|
* @description Check if margin manager has base asset debt
|
|
1061
|
-
* @param {string}
|
|
1062
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
1061
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
1063
1062
|
* @returns {Promise<boolean>} True if has base debt, false otherwise
|
|
1064
1063
|
*/
|
|
1065
|
-
async getMarginManagerHasBaseDebt(
|
|
1064
|
+
async getMarginManagerHasBaseDebt(marginManagerKey) {
|
|
1065
|
+
const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
|
|
1066
1066
|
const tx = new import_transactions.Transaction();
|
|
1067
|
-
tx.add(this.marginManager.hasBaseDebt(poolKey,
|
|
1067
|
+
tx.add(this.marginManager.hasBaseDebt(manager.poolKey, manager.address));
|
|
1068
1068
|
const res = await this.client.devInspectTransactionBlock({
|
|
1069
1069
|
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1070
1070
|
transactionBlock: tx
|
|
@@ -1074,13 +1074,13 @@ class DeepBookClient {
|
|
|
1074
1074
|
}
|
|
1075
1075
|
/**
|
|
1076
1076
|
* @description Get the balance manager ID for a margin manager
|
|
1077
|
-
* @param {string}
|
|
1078
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
1077
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
1079
1078
|
* @returns {Promise<string>} The balance manager ID
|
|
1080
1079
|
*/
|
|
1081
|
-
async getMarginManagerBalanceManagerId(
|
|
1080
|
+
async getMarginManagerBalanceManagerId(marginManagerKey) {
|
|
1081
|
+
const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
|
|
1082
1082
|
const tx = new import_transactions.Transaction();
|
|
1083
|
-
tx.add(this.marginManager.balanceManager(poolKey,
|
|
1083
|
+
tx.add(this.marginManager.balanceManager(manager.poolKey, manager.address));
|
|
1084
1084
|
const res = await this.client.devInspectTransactionBlock({
|
|
1085
1085
|
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1086
1086
|
transactionBlock: tx
|
|
@@ -1090,21 +1090,21 @@ class DeepBookClient {
|
|
|
1090
1090
|
}
|
|
1091
1091
|
/**
|
|
1092
1092
|
* @description Calculate assets (base and quote) for a margin manager
|
|
1093
|
-
* @param {string}
|
|
1094
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
1093
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
1095
1094
|
* @param {number} decimals Number of decimal places to show (default: 6)
|
|
1096
1095
|
* @returns {Promise<{baseAsset: string, quoteAsset: string}>} The base and quote assets
|
|
1097
1096
|
*/
|
|
1098
|
-
async getMarginManagerAssets(
|
|
1097
|
+
async getMarginManagerAssets(marginManagerKey, decimals = 6) {
|
|
1098
|
+
const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
|
|
1099
1099
|
const tx = new import_transactions.Transaction();
|
|
1100
|
-
tx.add(this.marginManager.calculateAssets(poolKey,
|
|
1100
|
+
tx.add(this.marginManager.calculateAssets(manager.poolKey, manager.address));
|
|
1101
1101
|
const res = await this.client.devInspectTransactionBlock({
|
|
1102
1102
|
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1103
1103
|
transactionBlock: tx
|
|
1104
1104
|
});
|
|
1105
1105
|
const baseBytes = res.results[0].returnValues[0][0];
|
|
1106
1106
|
const quoteBytes = res.results[0].returnValues[1][0];
|
|
1107
|
-
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1107
|
+
const pool = __privateGet(this, _config).getPool(manager.poolKey);
|
|
1108
1108
|
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
1109
1109
|
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
1110
1110
|
const baseAsset = __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(import_bcs.bcs.U64.parse(new Uint8Array(baseBytes))), baseCoin.scalar, decimals);
|
|
@@ -1115,17 +1115,17 @@ class DeepBookClient {
|
|
|
1115
1115
|
* @description Calculate debts (base and quote) for a margin manager
|
|
1116
1116
|
* NOTE: This function automatically determines whether to use base or quote margin pool
|
|
1117
1117
|
* based on hasBaseDebt. You don't need to specify the debt coin type.
|
|
1118
|
-
* @param {string}
|
|
1119
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
1118
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
1120
1119
|
* @param {number} decimals Number of decimal places to show (default: 6)
|
|
1121
1120
|
* @returns {Promise<{baseDebt: string, quoteDebt: string}>} The base and quote debts
|
|
1122
1121
|
*/
|
|
1123
|
-
async getMarginManagerDebts(
|
|
1124
|
-
const hasBaseDebt = await this.getMarginManagerHasBaseDebt(
|
|
1125
|
-
const
|
|
1122
|
+
async getMarginManagerDebts(marginManagerKey, decimals = 6) {
|
|
1123
|
+
const hasBaseDebt = await this.getMarginManagerHasBaseDebt(marginManagerKey);
|
|
1124
|
+
const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
|
|
1125
|
+
const pool = __privateGet(this, _config).getPool(manager.poolKey);
|
|
1126
1126
|
const debtCoinKey = hasBaseDebt ? pool.baseCoin : pool.quoteCoin;
|
|
1127
1127
|
const tx = new import_transactions.Transaction();
|
|
1128
|
-
tx.add(this.marginManager.calculateDebts(poolKey, debtCoinKey,
|
|
1128
|
+
tx.add(this.marginManager.calculateDebts(manager.poolKey, debtCoinKey, manager.address));
|
|
1129
1129
|
const res = await this.client.devInspectTransactionBlock({
|
|
1130
1130
|
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1131
1131
|
transactionBlock: tx
|
|
@@ -1142,6 +1142,73 @@ class DeepBookClient {
|
|
|
1142
1142
|
const quoteDebt = __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(import_bcs.bcs.U64.parse(new Uint8Array(quoteBytes))), debtCoin.scalar, decimals);
|
|
1143
1143
|
return { baseDebt, quoteDebt };
|
|
1144
1144
|
}
|
|
1145
|
+
/**
|
|
1146
|
+
* @description Get comprehensive state information for a margin manager
|
|
1147
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
1148
|
+
* @param {number} decimals Number of decimal places to show (default: 6)
|
|
1149
|
+
* @returns {Promise<{
|
|
1150
|
+
* managerId: string,
|
|
1151
|
+
* deepbookPoolId: string,
|
|
1152
|
+
* riskRatio: number,
|
|
1153
|
+
* baseAsset: string,
|
|
1154
|
+
* quoteAsset: string,
|
|
1155
|
+
* baseDebt: string,
|
|
1156
|
+
* quoteDebt: string,
|
|
1157
|
+
* basePythPrice: string,
|
|
1158
|
+
* basePythDecimals: number,
|
|
1159
|
+
* quotePythPrice: string,
|
|
1160
|
+
* quotePythDecimals: number
|
|
1161
|
+
* }>} Comprehensive margin manager state
|
|
1162
|
+
*/
|
|
1163
|
+
async getMarginManagerState(marginManagerKey, decimals = 6) {
|
|
1164
|
+
const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
|
|
1165
|
+
const tx = new import_transactions.Transaction();
|
|
1166
|
+
tx.add(this.marginManager.managerState(manager.poolKey, manager.address));
|
|
1167
|
+
const res = await this.client.devInspectTransactionBlock({
|
|
1168
|
+
sender: (0, import_utils.normalizeSuiAddress)(__privateGet(this, _address)),
|
|
1169
|
+
transactionBlock: tx
|
|
1170
|
+
});
|
|
1171
|
+
if (!res.results || !res.results[0] || !res.results[0].returnValues) {
|
|
1172
|
+
throw new Error(
|
|
1173
|
+
`Failed to get margin manager state: ${res.effects?.status?.error || "Unknown error"}`
|
|
1174
|
+
);
|
|
1175
|
+
}
|
|
1176
|
+
const pool = __privateGet(this, _config).getPool(manager.poolKey);
|
|
1177
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
1178
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
1179
|
+
const managerId = (0, import_utils.normalizeSuiAddress)(
|
|
1180
|
+
import_bcs.bcs.Address.parse(new Uint8Array(res.results[0].returnValues[0][0]))
|
|
1181
|
+
);
|
|
1182
|
+
const deepbookPoolId = (0, import_utils.normalizeSuiAddress)(
|
|
1183
|
+
import_bcs.bcs.Address.parse(new Uint8Array(res.results[0].returnValues[1][0]))
|
|
1184
|
+
);
|
|
1185
|
+
const riskRatio = Number(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0]))) / import_config.FLOAT_SCALAR;
|
|
1186
|
+
const baseAsset = __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[3][0]))), baseCoin.scalar, decimals);
|
|
1187
|
+
const quoteAsset = __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[4][0]))), quoteCoin.scalar, decimals);
|
|
1188
|
+
const baseDebt = __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[5][0]))), baseCoin.scalar, decimals);
|
|
1189
|
+
const quoteDebt = __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[6][0]))), quoteCoin.scalar, decimals);
|
|
1190
|
+
const basePythPrice = import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[7][0]));
|
|
1191
|
+
const basePythDecimals = Number(
|
|
1192
|
+
import_bcs.bcs.u8().parse(new Uint8Array(res.results[0].returnValues[8][0]))
|
|
1193
|
+
);
|
|
1194
|
+
const quotePythPrice = import_bcs.bcs.U64.parse(new Uint8Array(res.results[0].returnValues[9][0]));
|
|
1195
|
+
const quotePythDecimals = Number(
|
|
1196
|
+
import_bcs.bcs.u8().parse(new Uint8Array(res.results[0].returnValues[10][0]))
|
|
1197
|
+
);
|
|
1198
|
+
return {
|
|
1199
|
+
managerId,
|
|
1200
|
+
deepbookPoolId,
|
|
1201
|
+
riskRatio,
|
|
1202
|
+
baseAsset,
|
|
1203
|
+
quoteAsset,
|
|
1204
|
+
baseDebt,
|
|
1205
|
+
quoteDebt,
|
|
1206
|
+
basePythPrice: basePythPrice.toString(),
|
|
1207
|
+
basePythDecimals,
|
|
1208
|
+
quotePythPrice: quotePythPrice.toString(),
|
|
1209
|
+
quotePythDecimals
|
|
1210
|
+
};
|
|
1211
|
+
}
|
|
1145
1212
|
// === Margin Registry Functions ===
|
|
1146
1213
|
/**
|
|
1147
1214
|
* @description Check if a deepbook pool is enabled for margin trading
|