@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/dist/esm/client.js
CHANGED
|
@@ -940,13 +940,13 @@ class DeepBookClient {
|
|
|
940
940
|
// === Margin Manager Read-Only Functions ===
|
|
941
941
|
/**
|
|
942
942
|
* @description Get the owner address of a margin manager
|
|
943
|
-
* @param {string}
|
|
944
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
943
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
945
944
|
* @returns {Promise<string>} The owner address
|
|
946
945
|
*/
|
|
947
|
-
async getMarginManagerOwner(
|
|
946
|
+
async getMarginManagerOwner(marginManagerKey) {
|
|
947
|
+
const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
|
|
948
948
|
const tx = new Transaction();
|
|
949
|
-
tx.add(this.marginManager.ownerByPoolKey(poolKey,
|
|
949
|
+
tx.add(this.marginManager.ownerByPoolKey(manager.poolKey, manager.address));
|
|
950
950
|
const res = await this.client.devInspectTransactionBlock({
|
|
951
951
|
sender: normalizeSuiAddress(__privateGet(this, _address)),
|
|
952
952
|
transactionBlock: tx
|
|
@@ -956,13 +956,13 @@ class DeepBookClient {
|
|
|
956
956
|
}
|
|
957
957
|
/**
|
|
958
958
|
* @description Get the DeepBook pool ID associated with a margin manager
|
|
959
|
-
* @param {string}
|
|
960
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
959
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
961
960
|
* @returns {Promise<string>} The DeepBook pool ID
|
|
962
961
|
*/
|
|
963
|
-
async getMarginManagerDeepbookPool(
|
|
962
|
+
async getMarginManagerDeepbookPool(marginManagerKey) {
|
|
963
|
+
const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
|
|
964
964
|
const tx = new Transaction();
|
|
965
|
-
tx.add(this.marginManager.deepbookPool(poolKey,
|
|
965
|
+
tx.add(this.marginManager.deepbookPool(manager.poolKey, manager.address));
|
|
966
966
|
const res = await this.client.devInspectTransactionBlock({
|
|
967
967
|
sender: normalizeSuiAddress(__privateGet(this, _address)),
|
|
968
968
|
transactionBlock: tx
|
|
@@ -972,13 +972,13 @@ class DeepBookClient {
|
|
|
972
972
|
}
|
|
973
973
|
/**
|
|
974
974
|
* @description Get the margin pool ID (if any) associated with a margin manager
|
|
975
|
-
* @param {string}
|
|
976
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
975
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
977
976
|
* @returns {Promise<string | null>} The margin pool ID or null if no active loan
|
|
978
977
|
*/
|
|
979
|
-
async getMarginManagerMarginPoolId(
|
|
978
|
+
async getMarginManagerMarginPoolId(marginManagerKey) {
|
|
979
|
+
const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
|
|
980
980
|
const tx = new Transaction();
|
|
981
|
-
tx.add(this.marginManager.marginPoolId(poolKey,
|
|
981
|
+
tx.add(this.marginManager.marginPoolId(manager.poolKey, manager.address));
|
|
982
982
|
const res = await this.client.devInspectTransactionBlock({
|
|
983
983
|
sender: normalizeSuiAddress(__privateGet(this, _address)),
|
|
984
984
|
transactionBlock: tx
|
|
@@ -989,13 +989,13 @@ class DeepBookClient {
|
|
|
989
989
|
}
|
|
990
990
|
/**
|
|
991
991
|
* @description Get borrowed shares for both base and quote assets
|
|
992
|
-
* @param {string}
|
|
993
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
992
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
994
993
|
* @returns {Promise<{baseShares: string, quoteShares: string}>} The borrowed shares
|
|
995
994
|
*/
|
|
996
|
-
async getMarginManagerBorrowedShares(
|
|
995
|
+
async getMarginManagerBorrowedShares(marginManagerKey) {
|
|
996
|
+
const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
|
|
997
997
|
const tx = new Transaction();
|
|
998
|
-
tx.add(this.marginManager.borrowedShares(poolKey,
|
|
998
|
+
tx.add(this.marginManager.borrowedShares(manager.poolKey, manager.address));
|
|
999
999
|
const res = await this.client.devInspectTransactionBlock({
|
|
1000
1000
|
sender: normalizeSuiAddress(__privateGet(this, _address)),
|
|
1001
1001
|
transactionBlock: tx
|
|
@@ -1008,13 +1008,13 @@ class DeepBookClient {
|
|
|
1008
1008
|
}
|
|
1009
1009
|
/**
|
|
1010
1010
|
* @description Get borrowed base shares
|
|
1011
|
-
* @param {string}
|
|
1012
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
1011
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
1013
1012
|
* @returns {Promise<string>} The borrowed base shares
|
|
1014
1013
|
*/
|
|
1015
|
-
async getMarginManagerBorrowedBaseShares(
|
|
1014
|
+
async getMarginManagerBorrowedBaseShares(marginManagerKey) {
|
|
1015
|
+
const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
|
|
1016
1016
|
const tx = new Transaction();
|
|
1017
|
-
tx.add(this.marginManager.borrowedBaseShares(poolKey,
|
|
1017
|
+
tx.add(this.marginManager.borrowedBaseShares(manager.poolKey, manager.address));
|
|
1018
1018
|
const res = await this.client.devInspectTransactionBlock({
|
|
1019
1019
|
sender: normalizeSuiAddress(__privateGet(this, _address)),
|
|
1020
1020
|
transactionBlock: tx
|
|
@@ -1024,13 +1024,13 @@ class DeepBookClient {
|
|
|
1024
1024
|
}
|
|
1025
1025
|
/**
|
|
1026
1026
|
* @description Get borrowed quote shares
|
|
1027
|
-
* @param {string}
|
|
1028
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
1027
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
1029
1028
|
* @returns {Promise<string>} The borrowed quote shares
|
|
1030
1029
|
*/
|
|
1031
|
-
async getMarginManagerBorrowedQuoteShares(
|
|
1030
|
+
async getMarginManagerBorrowedQuoteShares(marginManagerKey) {
|
|
1031
|
+
const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
|
|
1032
1032
|
const tx = new Transaction();
|
|
1033
|
-
tx.add(this.marginManager.borrowedQuoteShares(poolKey,
|
|
1033
|
+
tx.add(this.marginManager.borrowedQuoteShares(manager.poolKey, manager.address));
|
|
1034
1034
|
const res = await this.client.devInspectTransactionBlock({
|
|
1035
1035
|
sender: normalizeSuiAddress(__privateGet(this, _address)),
|
|
1036
1036
|
transactionBlock: tx
|
|
@@ -1040,13 +1040,13 @@ class DeepBookClient {
|
|
|
1040
1040
|
}
|
|
1041
1041
|
/**
|
|
1042
1042
|
* @description Check if margin manager has base asset debt
|
|
1043
|
-
* @param {string}
|
|
1044
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
1043
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
1045
1044
|
* @returns {Promise<boolean>} True if has base debt, false otherwise
|
|
1046
1045
|
*/
|
|
1047
|
-
async getMarginManagerHasBaseDebt(
|
|
1046
|
+
async getMarginManagerHasBaseDebt(marginManagerKey) {
|
|
1047
|
+
const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
|
|
1048
1048
|
const tx = new Transaction();
|
|
1049
|
-
tx.add(this.marginManager.hasBaseDebt(poolKey,
|
|
1049
|
+
tx.add(this.marginManager.hasBaseDebt(manager.poolKey, manager.address));
|
|
1050
1050
|
const res = await this.client.devInspectTransactionBlock({
|
|
1051
1051
|
sender: normalizeSuiAddress(__privateGet(this, _address)),
|
|
1052
1052
|
transactionBlock: tx
|
|
@@ -1056,13 +1056,13 @@ class DeepBookClient {
|
|
|
1056
1056
|
}
|
|
1057
1057
|
/**
|
|
1058
1058
|
* @description Get the balance manager ID for a margin manager
|
|
1059
|
-
* @param {string}
|
|
1060
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
1059
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
1061
1060
|
* @returns {Promise<string>} The balance manager ID
|
|
1062
1061
|
*/
|
|
1063
|
-
async getMarginManagerBalanceManagerId(
|
|
1062
|
+
async getMarginManagerBalanceManagerId(marginManagerKey) {
|
|
1063
|
+
const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
|
|
1064
1064
|
const tx = new Transaction();
|
|
1065
|
-
tx.add(this.marginManager.balanceManager(poolKey,
|
|
1065
|
+
tx.add(this.marginManager.balanceManager(manager.poolKey, manager.address));
|
|
1066
1066
|
const res = await this.client.devInspectTransactionBlock({
|
|
1067
1067
|
sender: normalizeSuiAddress(__privateGet(this, _address)),
|
|
1068
1068
|
transactionBlock: tx
|
|
@@ -1072,21 +1072,21 @@ class DeepBookClient {
|
|
|
1072
1072
|
}
|
|
1073
1073
|
/**
|
|
1074
1074
|
* @description Calculate assets (base and quote) for a margin manager
|
|
1075
|
-
* @param {string}
|
|
1076
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
1075
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
1077
1076
|
* @param {number} decimals Number of decimal places to show (default: 6)
|
|
1078
1077
|
* @returns {Promise<{baseAsset: string, quoteAsset: string}>} The base and quote assets
|
|
1079
1078
|
*/
|
|
1080
|
-
async getMarginManagerAssets(
|
|
1079
|
+
async getMarginManagerAssets(marginManagerKey, decimals = 6) {
|
|
1080
|
+
const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
|
|
1081
1081
|
const tx = new Transaction();
|
|
1082
|
-
tx.add(this.marginManager.calculateAssets(poolKey,
|
|
1082
|
+
tx.add(this.marginManager.calculateAssets(manager.poolKey, manager.address));
|
|
1083
1083
|
const res = await this.client.devInspectTransactionBlock({
|
|
1084
1084
|
sender: normalizeSuiAddress(__privateGet(this, _address)),
|
|
1085
1085
|
transactionBlock: tx
|
|
1086
1086
|
});
|
|
1087
1087
|
const baseBytes = res.results[0].returnValues[0][0];
|
|
1088
1088
|
const quoteBytes = res.results[0].returnValues[1][0];
|
|
1089
|
-
const pool = __privateGet(this, _config).getPool(poolKey);
|
|
1089
|
+
const pool = __privateGet(this, _config).getPool(manager.poolKey);
|
|
1090
1090
|
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
1091
1091
|
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
1092
1092
|
const baseAsset = __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(bcs.U64.parse(new Uint8Array(baseBytes))), baseCoin.scalar, decimals);
|
|
@@ -1097,17 +1097,17 @@ class DeepBookClient {
|
|
|
1097
1097
|
* @description Calculate debts (base and quote) for a margin manager
|
|
1098
1098
|
* NOTE: This function automatically determines whether to use base or quote margin pool
|
|
1099
1099
|
* based on hasBaseDebt. You don't need to specify the debt coin type.
|
|
1100
|
-
* @param {string}
|
|
1101
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
1100
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
1102
1101
|
* @param {number} decimals Number of decimal places to show (default: 6)
|
|
1103
1102
|
* @returns {Promise<{baseDebt: string, quoteDebt: string}>} The base and quote debts
|
|
1104
1103
|
*/
|
|
1105
|
-
async getMarginManagerDebts(
|
|
1106
|
-
const hasBaseDebt = await this.getMarginManagerHasBaseDebt(
|
|
1107
|
-
const
|
|
1104
|
+
async getMarginManagerDebts(marginManagerKey, decimals = 6) {
|
|
1105
|
+
const hasBaseDebt = await this.getMarginManagerHasBaseDebt(marginManagerKey);
|
|
1106
|
+
const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
|
|
1107
|
+
const pool = __privateGet(this, _config).getPool(manager.poolKey);
|
|
1108
1108
|
const debtCoinKey = hasBaseDebt ? pool.baseCoin : pool.quoteCoin;
|
|
1109
1109
|
const tx = new Transaction();
|
|
1110
|
-
tx.add(this.marginManager.calculateDebts(poolKey, debtCoinKey,
|
|
1110
|
+
tx.add(this.marginManager.calculateDebts(manager.poolKey, debtCoinKey, manager.address));
|
|
1111
1111
|
const res = await this.client.devInspectTransactionBlock({
|
|
1112
1112
|
sender: normalizeSuiAddress(__privateGet(this, _address)),
|
|
1113
1113
|
transactionBlock: tx
|
|
@@ -1124,6 +1124,73 @@ class DeepBookClient {
|
|
|
1124
1124
|
const quoteDebt = __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(bcs.U64.parse(new Uint8Array(quoteBytes))), debtCoin.scalar, decimals);
|
|
1125
1125
|
return { baseDebt, quoteDebt };
|
|
1126
1126
|
}
|
|
1127
|
+
/**
|
|
1128
|
+
* @description Get comprehensive state information for a margin manager
|
|
1129
|
+
* @param {string} marginManagerKey The key to identify the margin manager
|
|
1130
|
+
* @param {number} decimals Number of decimal places to show (default: 6)
|
|
1131
|
+
* @returns {Promise<{
|
|
1132
|
+
* managerId: string,
|
|
1133
|
+
* deepbookPoolId: string,
|
|
1134
|
+
* riskRatio: number,
|
|
1135
|
+
* baseAsset: string,
|
|
1136
|
+
* quoteAsset: string,
|
|
1137
|
+
* baseDebt: string,
|
|
1138
|
+
* quoteDebt: string,
|
|
1139
|
+
* basePythPrice: string,
|
|
1140
|
+
* basePythDecimals: number,
|
|
1141
|
+
* quotePythPrice: string,
|
|
1142
|
+
* quotePythDecimals: number
|
|
1143
|
+
* }>} Comprehensive margin manager state
|
|
1144
|
+
*/
|
|
1145
|
+
async getMarginManagerState(marginManagerKey, decimals = 6) {
|
|
1146
|
+
const manager = __privateGet(this, _config).getMarginManager(marginManagerKey);
|
|
1147
|
+
const tx = new Transaction();
|
|
1148
|
+
tx.add(this.marginManager.managerState(manager.poolKey, manager.address));
|
|
1149
|
+
const res = await this.client.devInspectTransactionBlock({
|
|
1150
|
+
sender: normalizeSuiAddress(__privateGet(this, _address)),
|
|
1151
|
+
transactionBlock: tx
|
|
1152
|
+
});
|
|
1153
|
+
if (!res.results || !res.results[0] || !res.results[0].returnValues) {
|
|
1154
|
+
throw new Error(
|
|
1155
|
+
`Failed to get margin manager state: ${res.effects?.status?.error || "Unknown error"}`
|
|
1156
|
+
);
|
|
1157
|
+
}
|
|
1158
|
+
const pool = __privateGet(this, _config).getPool(manager.poolKey);
|
|
1159
|
+
const baseCoin = __privateGet(this, _config).getCoin(pool.baseCoin);
|
|
1160
|
+
const quoteCoin = __privateGet(this, _config).getCoin(pool.quoteCoin);
|
|
1161
|
+
const managerId = normalizeSuiAddress(
|
|
1162
|
+
bcs.Address.parse(new Uint8Array(res.results[0].returnValues[0][0]))
|
|
1163
|
+
);
|
|
1164
|
+
const deepbookPoolId = normalizeSuiAddress(
|
|
1165
|
+
bcs.Address.parse(new Uint8Array(res.results[0].returnValues[1][0]))
|
|
1166
|
+
);
|
|
1167
|
+
const riskRatio = Number(bcs.U64.parse(new Uint8Array(res.results[0].returnValues[2][0]))) / FLOAT_SCALAR;
|
|
1168
|
+
const baseAsset = __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(bcs.U64.parse(new Uint8Array(res.results[0].returnValues[3][0]))), baseCoin.scalar, decimals);
|
|
1169
|
+
const quoteAsset = __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(bcs.U64.parse(new Uint8Array(res.results[0].returnValues[4][0]))), quoteCoin.scalar, decimals);
|
|
1170
|
+
const baseDebt = __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(bcs.U64.parse(new Uint8Array(res.results[0].returnValues[5][0]))), baseCoin.scalar, decimals);
|
|
1171
|
+
const quoteDebt = __privateMethod(this, _DeepBookClient_instances, formatTokenAmount_fn).call(this, BigInt(bcs.U64.parse(new Uint8Array(res.results[0].returnValues[6][0]))), quoteCoin.scalar, decimals);
|
|
1172
|
+
const basePythPrice = bcs.U64.parse(new Uint8Array(res.results[0].returnValues[7][0]));
|
|
1173
|
+
const basePythDecimals = Number(
|
|
1174
|
+
bcs.u8().parse(new Uint8Array(res.results[0].returnValues[8][0]))
|
|
1175
|
+
);
|
|
1176
|
+
const quotePythPrice = bcs.U64.parse(new Uint8Array(res.results[0].returnValues[9][0]));
|
|
1177
|
+
const quotePythDecimals = Number(
|
|
1178
|
+
bcs.u8().parse(new Uint8Array(res.results[0].returnValues[10][0]))
|
|
1179
|
+
);
|
|
1180
|
+
return {
|
|
1181
|
+
managerId,
|
|
1182
|
+
deepbookPoolId,
|
|
1183
|
+
riskRatio,
|
|
1184
|
+
baseAsset,
|
|
1185
|
+
quoteAsset,
|
|
1186
|
+
baseDebt,
|
|
1187
|
+
quoteDebt,
|
|
1188
|
+
basePythPrice: basePythPrice.toString(),
|
|
1189
|
+
basePythDecimals,
|
|
1190
|
+
quotePythPrice: quotePythPrice.toString(),
|
|
1191
|
+
quotePythDecimals
|
|
1192
|
+
};
|
|
1193
|
+
}
|
|
1127
1194
|
// === Margin Registry Functions ===
|
|
1128
1195
|
/**
|
|
1129
1196
|
* @description Check if a deepbook pool is enabled for margin trading
|