@mysten/deepbook-v3 1.0.8 → 1.0.10
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 +13 -0
- package/dist/client.d.mts +18 -0
- package/dist/client.d.mts.map +1 -1
- package/dist/client.mjs +83 -0
- package/dist/client.mjs.map +1 -1
- package/dist/utils/constants.mjs +5 -5
- package/dist/utils/constants.mjs.map +1 -1
- package/package.json +4 -4
- package/src/client.ts +142 -0
- package/src/utils/constants.ts +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @mysten/deepbook-v3
|
|
2
2
|
|
|
3
|
+
## 1.0.10
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 05765dc: checkManagerBalancesWithAddress and getMarginManagerBalances added to support querying
|
|
8
|
+
balnces in a single RPC call for multiple managers and assets
|
|
9
|
+
|
|
10
|
+
## 1.0.9
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 5b220df: Update USDE to SUIUSDE in constants
|
|
15
|
+
|
|
3
16
|
## 1.0.8
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/dist/client.d.mts
CHANGED
|
@@ -94,6 +94,13 @@ declare class DeepBookClient {
|
|
|
94
94
|
coinType: string;
|
|
95
95
|
balance: number;
|
|
96
96
|
}>;
|
|
97
|
+
/**
|
|
98
|
+
* @description Check multiple coin balances for multiple balance managers by address in a single dry run call
|
|
99
|
+
* @param {string[]} managerAddresses The on-chain addresses of the BalanceManagers
|
|
100
|
+
* @param {string[]} coinKeys Keys of the coins to check balances for
|
|
101
|
+
* @returns {Promise<Record<string, Record<string, number>>>} Object keyed by manager address, mapping coinType to balance
|
|
102
|
+
*/
|
|
103
|
+
checkManagerBalancesWithAddress(managerAddresses: string[], coinKeys: string[]): Promise<Record<string, Record<string, number>>>;
|
|
97
104
|
/**
|
|
98
105
|
* @description Check if a pool is whitelisted
|
|
99
106
|
* @param {string} poolKey Key of the pool
|
|
@@ -659,6 +666,17 @@ declare class DeepBookClient {
|
|
|
659
666
|
* @returns {Promise<string>} The DEEP token balance
|
|
660
667
|
*/
|
|
661
668
|
getMarginManagerDeepBalance(marginManagerKey: string, decimals?: number): Promise<string>;
|
|
669
|
+
/**
|
|
670
|
+
* @description Get base, quote, and DEEP balances for multiple margin managers in a single dry run call
|
|
671
|
+
* @param {Record<string, string>} marginManagers Map of marginManagerId -> poolKey
|
|
672
|
+
* @param {number} decimals Number of decimal places for formatting (default: 9)
|
|
673
|
+
* @returns {Promise<Record<string, { base: string, quote: string, deep: string }>>} Object keyed by managerId
|
|
674
|
+
*/
|
|
675
|
+
getMarginManagerBalances(marginManagers: Record<string, string>, decimals?: number): Promise<Record<string, {
|
|
676
|
+
base: string;
|
|
677
|
+
quote: string;
|
|
678
|
+
deep: string;
|
|
679
|
+
}>>;
|
|
662
680
|
/**
|
|
663
681
|
* @description Get account order details for a margin manager.
|
|
664
682
|
* This retrieves the balance manager from the margin manager and returns order details.
|
package/dist/client.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.mts","names":[],"sources":["../src/client.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;;;;;;UAsCiB,wBAAA,SAAiC;AAAjC,UAEA,eAFyB,CAAA,OAAA,UAAQ,CAAA,CAAA;EAEjC,OAAA,EAAA,MAAA;EAEmB,eAAA,CAAA,EAAA;IACD,CAAA,GAAA,EAAA,MAAA,CAAA,EADC,cACD;EAC1B,CAAA;EACA,cAAA,CAAA,EAAA;IAID,CAAA,GAAA,EAAA,MAAA,CAAA,EAN2B,aAM3B;EAAI,CAAA;EAGK,KAAA,CAAA,EARR,OAQQ;EACR,KAAA,CAAA,EARA,OAQA;EACC,QAAA,CAAA,EAAA,MAAe;EAFsB,cAAA,CAAA,EAAA,MAAA;EAAe,mBAAA,CAAA,EAAA,MAAA;E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|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
129
|
/**
|
|
130
|
+
* @description Check multiple coin balances for multiple balance managers by address in a single dry run call
|
|
131
|
+
* @param {string[]} managerAddresses The on-chain addresses of the BalanceManagers
|
|
132
|
+
* @param {string[]} coinKeys Keys of the coins to check balances for
|
|
133
|
+
* @returns {Promise<Record<string, Record<string, number>>>} Object keyed by manager address, mapping coinType to balance
|
|
134
|
+
*/
|
|
135
|
+
async checkManagerBalancesWithAddress(managerAddresses, coinKeys) {
|
|
136
|
+
if (managerAddresses.length === 0 || coinKeys.length === 0) return {};
|
|
137
|
+
const tx = new Transaction();
|
|
138
|
+
const coins = coinKeys.map((coinKey) => this.#config.getCoin(coinKey));
|
|
139
|
+
for (const managerAddress of managerAddresses) for (const coin of coins) tx.moveCall({
|
|
140
|
+
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::balance_manager::balance`,
|
|
141
|
+
arguments: [tx.object(managerAddress)],
|
|
142
|
+
typeArguments: [coin.type]
|
|
143
|
+
});
|
|
144
|
+
const res = await this.#client.core.simulateTransaction({
|
|
145
|
+
transaction: tx,
|
|
146
|
+
include: {
|
|
147
|
+
commandResults: true,
|
|
148
|
+
effects: true
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
if (res.FailedTransaction) throw new Error(`Transaction failed: ${res.FailedTransaction.status.error?.message || "Unknown error"}`);
|
|
152
|
+
if (!res.commandResults) throw new Error("Failed to get manager balances: No command results");
|
|
153
|
+
const results = {};
|
|
154
|
+
for (let m = 0; m < managerAddresses.length; m++) {
|
|
155
|
+
const managerAddress = managerAddresses[m];
|
|
156
|
+
const managerBalances = {};
|
|
157
|
+
for (let c = 0; c < coins.length; c++) {
|
|
158
|
+
const coin = coins[c];
|
|
159
|
+
const commandResult = res.commandResults[m * coins.length + c];
|
|
160
|
+
if (!commandResult || !commandResult.returnValues) throw new Error(`Failed to get balance for ${coin.type}: No return values`);
|
|
161
|
+
const bytes = commandResult.returnValues[0].bcs;
|
|
162
|
+
const parsed_balance = bcs.U64.parse(bytes);
|
|
163
|
+
managerBalances[coin.type] = Number((Number(parsed_balance) / coin.scalar).toFixed(9));
|
|
164
|
+
}
|
|
165
|
+
results[managerAddress] = managerBalances;
|
|
166
|
+
}
|
|
167
|
+
return results;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
130
170
|
* @description Check if a pool is whitelisted
|
|
131
171
|
* @param {string} poolKey Key of the pool
|
|
132
172
|
* @returns {Promise<boolean>} Boolean indicating if the pool is whitelisted
|
|
@@ -1517,6 +1557,49 @@ var DeepBookClient = class {
|
|
|
1517
1557
|
return this.#formatTokenAmount(BigInt(bcs.U64.parse(bytes)), deepCoin.scalar, decimals);
|
|
1518
1558
|
}
|
|
1519
1559
|
/**
|
|
1560
|
+
* @description Get base, quote, and DEEP balances for multiple margin managers in a single dry run call
|
|
1561
|
+
* @param {Record<string, string>} marginManagers Map of marginManagerId -> poolKey
|
|
1562
|
+
* @param {number} decimals Number of decimal places for formatting (default: 9)
|
|
1563
|
+
* @returns {Promise<Record<string, { base: string, quote: string, deep: string }>>} Object keyed by managerId
|
|
1564
|
+
*/
|
|
1565
|
+
async getMarginManagerBalances(marginManagers, decimals = 9) {
|
|
1566
|
+
const entries = Object.entries(marginManagers);
|
|
1567
|
+
if (entries.length === 0) return {};
|
|
1568
|
+
const tx = new Transaction();
|
|
1569
|
+
for (const [managerId, poolKey] of entries) {
|
|
1570
|
+
tx.add(this.marginManager.baseBalance(poolKey, managerId));
|
|
1571
|
+
tx.add(this.marginManager.quoteBalance(poolKey, managerId));
|
|
1572
|
+
tx.add(this.marginManager.deepBalance(poolKey, managerId));
|
|
1573
|
+
}
|
|
1574
|
+
const res = await this.#client.core.simulateTransaction({
|
|
1575
|
+
transaction: tx,
|
|
1576
|
+
include: {
|
|
1577
|
+
commandResults: true,
|
|
1578
|
+
effects: true
|
|
1579
|
+
}
|
|
1580
|
+
});
|
|
1581
|
+
if (res.FailedTransaction) throw new Error(`Transaction failed: ${res.FailedTransaction.status.error?.message || "Unknown error"}`);
|
|
1582
|
+
if (!res.commandResults) throw new Error("Failed to get margin manager balances: No command results");
|
|
1583
|
+
const results = {};
|
|
1584
|
+
const deepCoin = this.#config.getCoin("DEEP");
|
|
1585
|
+
for (let i = 0; i < entries.length; i++) {
|
|
1586
|
+
const [managerId, poolKey] = entries[i];
|
|
1587
|
+
const pool = this.#config.getPool(poolKey);
|
|
1588
|
+
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
1589
|
+
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
1590
|
+
const baseResult = res.commandResults[i * 3];
|
|
1591
|
+
const quoteResult = res.commandResults[i * 3 + 1];
|
|
1592
|
+
const deepResult = res.commandResults[i * 3 + 2];
|
|
1593
|
+
if (!baseResult?.returnValues || !quoteResult?.returnValues || !deepResult?.returnValues) throw new Error(`Failed to get balances for margin manager ${managerId}: No return values`);
|
|
1594
|
+
results[managerId] = {
|
|
1595
|
+
base: this.#formatTokenAmount(BigInt(bcs.U64.parse(baseResult.returnValues[0].bcs)), baseCoin.scalar, decimals),
|
|
1596
|
+
quote: this.#formatTokenAmount(BigInt(bcs.U64.parse(quoteResult.returnValues[0].bcs)), quoteCoin.scalar, decimals),
|
|
1597
|
+
deep: this.#formatTokenAmount(BigInt(bcs.U64.parse(deepResult.returnValues[0].bcs)), deepCoin.scalar, decimals)
|
|
1598
|
+
};
|
|
1599
|
+
}
|
|
1600
|
+
return results;
|
|
1601
|
+
}
|
|
1602
|
+
/**
|
|
1520
1603
|
* @description Get account order details for a margin manager.
|
|
1521
1604
|
* This retrieves the balance manager from the margin manager and returns order details.
|
|
1522
1605
|
* @param {string} marginManagerKey The key to identify the margin manager
|