@mysten/deepbook-v3 1.1.0 → 1.1.1
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 +6 -0
- package/dist/client.d.mts +2 -23
- package/dist/client.d.mts.map +1 -1
- package/dist/client.mjs +14 -40
- package/dist/client.mjs.map +1 -1
- package/dist/transactions/marginLiquidations.d.mts +3 -3
- package/dist/transactions/marginManager.d.mts +0 -8
- package/dist/transactions/marginManager.d.mts.map +1 -1
- package/dist/transactions/marginManager.mjs +0 -15
- package/dist/transactions/marginManager.mjs.map +1 -1
- package/dist/transactions/marginPool.d.mts +18 -18
- package/dist/transactions/marginRegistry.d.mts +15 -15
- package/dist/transactions/marginTPSL.d.mts +9 -9
- package/dist/transactions/poolProxy.d.mts +5 -5
- package/package.json +1 -1
- package/src/client.ts +20 -46
- package/src/transactions/marginManager.ts +0 -28
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MarginProposalParams, PlaceMarginLimitOrderParams, PlaceMarginMarketOrderParams } from "../types/index.mjs";
|
|
2
2
|
import { DeepBookConfig } from "../utils/config.mjs";
|
|
3
|
-
import * as
|
|
3
|
+
import * as _mysten_sui_transactions79 from "@mysten/sui/transactions";
|
|
4
4
|
import { Transaction } from "@mysten/sui/transactions";
|
|
5
5
|
|
|
6
6
|
//#region src/transactions/poolProxy.d.ts
|
|
@@ -18,25 +18,25 @@ declare class PoolProxyContract {
|
|
|
18
18
|
* @param {PlaceMarginLimitOrderParams} params Parameters for placing a limit order
|
|
19
19
|
* @returns A function that takes a Transaction object
|
|
20
20
|
*/
|
|
21
|
-
placeLimitOrder: (params: PlaceMarginLimitOrderParams) => (tx: Transaction) =>
|
|
21
|
+
placeLimitOrder: (params: PlaceMarginLimitOrderParams) => (tx: Transaction) => _mysten_sui_transactions79.TransactionResult;
|
|
22
22
|
/**
|
|
23
23
|
* @description Place a market order
|
|
24
24
|
* @param {PlaceMarginMarketOrderParams} params Parameters for placing a market order
|
|
25
25
|
* @returns A function that takes a Transaction object
|
|
26
26
|
*/
|
|
27
|
-
placeMarketOrder: (params: PlaceMarginMarketOrderParams) => (tx: Transaction) =>
|
|
27
|
+
placeMarketOrder: (params: PlaceMarginMarketOrderParams) => (tx: Transaction) => _mysten_sui_transactions79.TransactionResult;
|
|
28
28
|
/**
|
|
29
29
|
* @description Place a reduce only limit order
|
|
30
30
|
* @param {PlaceMarginLimitOrderParams} params Parameters for placing a reduce only limit order
|
|
31
31
|
* @returns A function that takes a Transaction object
|
|
32
32
|
*/
|
|
33
|
-
placeReduceOnlyLimitOrder: (params: PlaceMarginLimitOrderParams) => (tx: Transaction) =>
|
|
33
|
+
placeReduceOnlyLimitOrder: (params: PlaceMarginLimitOrderParams) => (tx: Transaction) => _mysten_sui_transactions79.TransactionResult;
|
|
34
34
|
/**
|
|
35
35
|
* @description Place a reduce only market order
|
|
36
36
|
* @param {PlaceMarginMarketOrderParams} params Parameters for placing a reduce only market order
|
|
37
37
|
* @returns A function that takes a Transaction object
|
|
38
38
|
*/
|
|
39
|
-
placeReduceOnlyMarketOrder: (params: PlaceMarginMarketOrderParams) => (tx: Transaction) =>
|
|
39
|
+
placeReduceOnlyMarketOrder: (params: PlaceMarginMarketOrderParams) => (tx: Transaction) => _mysten_sui_transactions79.TransactionResult;
|
|
40
40
|
/**
|
|
41
41
|
* @description Modify an existing order
|
|
42
42
|
* @param {string} marginManagerKey The key to identify the MarginManager
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -1571,21 +1571,31 @@ export class DeepBookClient {
|
|
|
1571
1571
|
|
|
1572
1572
|
/**
|
|
1573
1573
|
* @description Get the balance manager ID for a margin manager
|
|
1574
|
-
* @param {string}
|
|
1574
|
+
* @param {string} marginManagerAddress The object ID of the margin manager
|
|
1575
1575
|
* @returns {Promise<string>} The balance manager ID
|
|
1576
1576
|
*/
|
|
1577
|
-
async getMarginManagerBalanceManagerId(
|
|
1578
|
-
const
|
|
1579
|
-
|
|
1580
|
-
|
|
1577
|
+
async getMarginManagerBalanceManagerId(marginManagerAddress: string): Promise<string> {
|
|
1578
|
+
const res = await this.#client.core.getObject({
|
|
1579
|
+
objectId: marginManagerAddress,
|
|
1580
|
+
include: { content: true },
|
|
1581
|
+
});
|
|
1581
1582
|
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1583
|
+
if (!res.object?.content) {
|
|
1584
|
+
throw new Error(`Margin manager not found: ${marginManagerAddress}`);
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
// MarginManager struct field order: id, owner, deepbook_pool, margin_pool_id, balance_manager
|
|
1588
|
+
// We only need to parse up to balance_manager's id (first field of BalanceManager)
|
|
1589
|
+
const MarginManagerBalanceManagerId = bcs.struct('MarginManagerBalanceManagerId', {
|
|
1590
|
+
id: bcs.Address,
|
|
1591
|
+
owner: bcs.Address,
|
|
1592
|
+
deepbook_pool: bcs.Address,
|
|
1593
|
+
margin_pool_id: bcs.option(bcs.Address),
|
|
1594
|
+
balance_manager_id: bcs.Address,
|
|
1585
1595
|
});
|
|
1586
1596
|
|
|
1587
|
-
const
|
|
1588
|
-
return normalizeSuiAddress(
|
|
1597
|
+
const parsed = MarginManagerBalanceManagerId.parse(res.object.content);
|
|
1598
|
+
return normalizeSuiAddress(parsed.balance_manager_id);
|
|
1589
1599
|
}
|
|
1590
1600
|
|
|
1591
1601
|
/**
|
|
@@ -2140,42 +2150,6 @@ export class DeepBookClient {
|
|
|
2140
2150
|
return results;
|
|
2141
2151
|
}
|
|
2142
2152
|
|
|
2143
|
-
/**
|
|
2144
|
-
* @description Get account order details for a margin manager.
|
|
2145
|
-
* This retrieves the balance manager from the margin manager and returns order details.
|
|
2146
|
-
* @param {string} marginManagerKey The key to identify the margin manager
|
|
2147
|
-
* @returns {Promise<Array>} Array of order details
|
|
2148
|
-
*/
|
|
2149
|
-
async getMarginAccountOrderDetails(marginManagerKey: string) {
|
|
2150
|
-
const manager = this.#config.getMarginManager(marginManagerKey);
|
|
2151
|
-
const tx = new Transaction();
|
|
2152
|
-
tx.add(this.marginManager.getMarginAccountOrderDetails(manager.poolKey, manager.address));
|
|
2153
|
-
|
|
2154
|
-
tx.setSenderIfNotSet(normalizeSuiAddress(this.#address));
|
|
2155
|
-
|
|
2156
|
-
const res = await this.#client.core.simulateTransaction({
|
|
2157
|
-
transaction: tx,
|
|
2158
|
-
include: { commandResults: true, effects: true },
|
|
2159
|
-
});
|
|
2160
|
-
|
|
2161
|
-
if (res.FailedTransaction) {
|
|
2162
|
-
throw new Error(
|
|
2163
|
-
`Transaction failed: ${res.FailedTransaction.status.error?.message || 'Unknown error'}`,
|
|
2164
|
-
);
|
|
2165
|
-
}
|
|
2166
|
-
|
|
2167
|
-
if (!res.commandResults || !res.commandResults[0] || !res.commandResults[0].returnValues) {
|
|
2168
|
-
throw new Error(`Failed to get conditional order IDs: Unknown error`);
|
|
2169
|
-
}
|
|
2170
|
-
|
|
2171
|
-
try {
|
|
2172
|
-
const bytes = res.commandResults[1].returnValues[0].bcs;
|
|
2173
|
-
return bcs.vector(Order).parse(bytes);
|
|
2174
|
-
} catch {
|
|
2175
|
-
return [];
|
|
2176
|
-
}
|
|
2177
|
-
}
|
|
2178
|
-
|
|
2179
2153
|
// === Margin TPSL (Take Profit / Stop Loss) Read-Only Functions ===
|
|
2180
2154
|
|
|
2181
2155
|
/**
|
|
@@ -753,32 +753,4 @@ export class MarginManagerContract {
|
|
|
753
753
|
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
754
754
|
});
|
|
755
755
|
};
|
|
756
|
-
|
|
757
|
-
/**
|
|
758
|
-
* @description Get account order details for a margin manager.
|
|
759
|
-
* This retrieves the balance manager from the margin manager and calls get_account_order_details.
|
|
760
|
-
* @param {string} poolKey The key to identify the pool
|
|
761
|
-
* @param {string} marginManagerId The ID of the margin manager
|
|
762
|
-
* @returns A function that takes a Transaction object
|
|
763
|
-
*/
|
|
764
|
-
getMarginAccountOrderDetails =
|
|
765
|
-
(poolKey: string, marginManagerId: string) => (tx: Transaction) => {
|
|
766
|
-
const pool = this.#config.getPool(poolKey);
|
|
767
|
-
const baseCoin = this.#config.getCoin(pool.baseCoin);
|
|
768
|
-
const quoteCoin = this.#config.getCoin(pool.quoteCoin);
|
|
769
|
-
|
|
770
|
-
// Get the balance manager from the margin manager
|
|
771
|
-
const balanceManager = tx.moveCall({
|
|
772
|
-
target: `${this.#config.MARGIN_PACKAGE_ID}::margin_manager::balance_manager`,
|
|
773
|
-
arguments: [tx.object(marginManagerId)],
|
|
774
|
-
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
775
|
-
});
|
|
776
|
-
|
|
777
|
-
// Call get_account_order_details with the balance manager
|
|
778
|
-
return tx.moveCall({
|
|
779
|
-
target: `${this.#config.DEEPBOOK_PACKAGE_ID}::pool::get_account_order_details`,
|
|
780
|
-
arguments: [tx.object(pool.address), balanceManager],
|
|
781
|
-
typeArguments: [baseCoin.type, quoteCoin.type],
|
|
782
|
-
});
|
|
783
|
-
};
|
|
784
756
|
}
|