@mysten/deepbook-v3 1.1.5 → 1.2.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 +23 -0
- package/dist/client.d.mts +58 -763
- package/dist/client.d.mts.map +1 -1
- package/dist/client.mjs +253 -2127
- package/dist/client.mjs.map +1 -1
- package/dist/contracts/utils/index.mjs +1 -1
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +4 -4
- package/dist/pyth/pyth.mjs +1 -1
- package/dist/queries/accountQueries.mjs +104 -0
- package/dist/queries/accountQueries.mjs.map +1 -0
- package/dist/queries/balanceManagerQueries.mjs +113 -0
- package/dist/queries/balanceManagerQueries.mjs.map +1 -0
- package/dist/queries/context.mjs +15 -0
- package/dist/queries/context.mjs.map +1 -0
- package/dist/queries/marginManagerQueries.mjs +365 -0
- package/dist/queries/marginManagerQueries.mjs.map +1 -0
- package/dist/queries/marginPoolQueries.mjs +184 -0
- package/dist/queries/marginPoolQueries.mjs.map +1 -0
- package/dist/queries/orderQueries.mjs +165 -0
- package/dist/queries/orderQueries.mjs.map +1 -0
- package/dist/queries/poolQueries.mjs +234 -0
- package/dist/queries/poolQueries.mjs.map +1 -0
- package/dist/queries/priceFeedQueries.mjs +83 -0
- package/dist/queries/priceFeedQueries.mjs.map +1 -0
- package/dist/queries/quantityQueries.mjs +216 -0
- package/dist/queries/quantityQueries.mjs.map +1 -0
- package/dist/queries/referralQueries.mjs +96 -0
- package/dist/queries/referralQueries.mjs.map +1 -0
- package/dist/queries/registryQueries.mjs +162 -0
- package/dist/queries/registryQueries.mjs.map +1 -0
- package/dist/queries/tpslQueries.mjs +62 -0
- package/dist/queries/tpslQueries.mjs.map +1 -0
- package/dist/transactions/balanceManager.d.mts +12 -12
- package/dist/transactions/balanceManager.d.mts.map +1 -1
- package/dist/transactions/balanceManager.mjs +5 -4
- package/dist/transactions/balanceManager.mjs.map +1 -1
- package/dist/transactions/deepbook.d.mts +24 -24
- package/dist/transactions/deepbook.d.mts.map +1 -1
- package/dist/transactions/deepbook.mjs +48 -47
- package/dist/transactions/deepbook.mjs.map +1 -1
- package/dist/transactions/deepbookAdmin.d.mts +2 -2
- package/dist/transactions/deepbookAdmin.d.mts.map +1 -1
- package/dist/transactions/deepbookAdmin.mjs +10 -9
- package/dist/transactions/deepbookAdmin.mjs.map +1 -1
- package/dist/transactions/flashLoans.d.mts.map +1 -1
- package/dist/transactions/flashLoans.mjs +6 -4
- package/dist/transactions/flashLoans.mjs.map +1 -1
- package/dist/transactions/governance.d.mts.map +1 -1
- package/dist/transactions/governance.mjs +5 -4
- package/dist/transactions/governance.mjs.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 +8 -7
- package/dist/transactions/marginAdmin.mjs.map +1 -1
- package/dist/transactions/marginLiquidations.d.mts.map +1 -1
- package/dist/transactions/marginLiquidations.mjs +5 -4
- package/dist/transactions/marginLiquidations.mjs.map +1 -1
- package/dist/transactions/marginMaintainer.d.mts +5 -5
- package/dist/transactions/marginMaintainer.d.mts.map +1 -1
- package/dist/transactions/marginMaintainer.mjs +15 -14
- package/dist/transactions/marginMaintainer.mjs.map +1 -1
- package/dist/transactions/marginManager.d.mts +23 -23
- package/dist/transactions/marginManager.d.mts.map +1 -1
- package/dist/transactions/marginManager.mjs +17 -12
- package/dist/transactions/marginManager.mjs.map +1 -1
- package/dist/transactions/marginPool.d.mts.map +1 -1
- package/dist/transactions/marginPool.mjs +3 -2
- package/dist/transactions/marginPool.mjs.map +1 -1
- package/dist/transactions/marginTPSL.d.mts +1 -1
- package/dist/transactions/marginTPSL.d.mts.map +1 -1
- package/dist/transactions/marginTPSL.mjs +6 -8
- package/dist/transactions/marginTPSL.mjs.map +1 -1
- package/dist/transactions/poolProxy.d.mts.map +1 -1
- package/dist/transactions/poolProxy.mjs +13 -13
- package/dist/transactions/poolProxy.mjs.map +1 -1
- package/dist/types/index.d.mts +189 -52
- package/dist/types/index.d.mts.map +1 -1
- package/dist/types/index.mjs.map +1 -1
- package/dist/utils/constants.d.mts +4 -0
- package/dist/utils/constants.d.mts.map +1 -1
- package/dist/utils/constants.mjs +12 -5
- package/dist/utils/constants.mjs.map +1 -1
- package/dist/utils/conversion.mjs +26 -0
- package/dist/utils/conversion.mjs.map +1 -0
- package/package.json +6 -5
- package/src/client.ts +421 -2662
- package/src/index.ts +27 -0
- package/src/queries/accountQueries.ts +117 -0
- package/src/queries/balanceManagerQueries.ts +156 -0
- package/src/queries/context.ts +44 -0
- package/src/queries/index.ts +16 -0
- package/src/queries/marginManagerQueries.ts +575 -0
- package/src/queries/marginPoolQueries.ts +226 -0
- package/src/queries/orderQueries.ts +202 -0
- package/src/queries/poolQueries.ts +266 -0
- package/src/queries/priceFeedQueries.ts +141 -0
- package/src/queries/quantityQueries.ts +266 -0
- package/src/queries/referralQueries.ts +112 -0
- package/src/queries/registryQueries.ts +185 -0
- package/src/queries/tpslQueries.ts +88 -0
- package/src/transactions/balanceManager.ts +5 -4
- package/src/transactions/deepbook.ts +98 -84
- package/src/transactions/deepbookAdmin.ts +10 -9
- package/src/transactions/flashLoans.ts +5 -4
- package/src/transactions/governance.ts +5 -4
- package/src/transactions/marginAdmin.ts +8 -7
- package/src/transactions/marginLiquidations.ts +5 -4
- package/src/transactions/marginMaintainer.ts +15 -14
- package/src/transactions/marginManager.ts +13 -12
- package/src/transactions/marginPool.ts +3 -2
- package/src/transactions/marginTPSL.ts +11 -6
- package/src/transactions/poolProxy.ts +12 -11
- package/src/types/index.ts +200 -53
- package/src/utils/constants.ts +12 -5
- package/src/utils/conversion.ts +33 -0
package/src/index.ts
CHANGED
|
@@ -37,6 +37,33 @@ export type {
|
|
|
37
37
|
Config,
|
|
38
38
|
} from './types/index.js';
|
|
39
39
|
|
|
40
|
+
// Named return types
|
|
41
|
+
export type {
|
|
42
|
+
ManagerBalance,
|
|
43
|
+
VaultBalances,
|
|
44
|
+
LockedBalances,
|
|
45
|
+
ReferralBalances,
|
|
46
|
+
PoolTradeParams,
|
|
47
|
+
PoolBookParams,
|
|
48
|
+
PoolDeepPrice,
|
|
49
|
+
QuoteQuantityOut,
|
|
50
|
+
BaseQuantityOut,
|
|
51
|
+
QuantityOut,
|
|
52
|
+
BaseQuantityIn,
|
|
53
|
+
QuoteQuantityIn,
|
|
54
|
+
OrderDeepRequiredResult,
|
|
55
|
+
Level2Range,
|
|
56
|
+
Level2TicksFromMid,
|
|
57
|
+
AccountBalances,
|
|
58
|
+
AccountInfo,
|
|
59
|
+
DecodedOrderId,
|
|
60
|
+
MarginManagerState,
|
|
61
|
+
MarginManagerAssets,
|
|
62
|
+
MarginManagerDebts,
|
|
63
|
+
MarginManagerBalancesResult,
|
|
64
|
+
BorrowedShares,
|
|
65
|
+
} from './types/index.js';
|
|
66
|
+
|
|
40
67
|
// Trading parameter interfaces
|
|
41
68
|
export type {
|
|
42
69
|
PlaceLimitOrderParams,
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
5
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
6
|
+
|
|
7
|
+
import { Account, OrderDeepPrice } from '../types/bcs.js';
|
|
8
|
+
import type { AccountInfo, LockedBalances, PoolDeepPrice } from '../types/index.js';
|
|
9
|
+
import { DEEP_SCALAR, FLOAT_SCALAR } from '../utils/config.js';
|
|
10
|
+
import type { QueryContext } from './context.js';
|
|
11
|
+
|
|
12
|
+
export class AccountQueries {
|
|
13
|
+
#ctx: QueryContext;
|
|
14
|
+
|
|
15
|
+
constructor(ctx: QueryContext) {
|
|
16
|
+
this.#ctx = ctx;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async account(poolKey: string, managerKey: string): Promise<AccountInfo> {
|
|
20
|
+
const tx = new Transaction();
|
|
21
|
+
const pool = this.#ctx.config.getPool(poolKey);
|
|
22
|
+
const baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;
|
|
23
|
+
const quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;
|
|
24
|
+
|
|
25
|
+
tx.add(this.#ctx.deepBook.account(poolKey, managerKey));
|
|
26
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
27
|
+
transaction: tx,
|
|
28
|
+
include: { commandResults: true, effects: true },
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const accountInformation = res.commandResults![0].returnValues[0].bcs;
|
|
32
|
+
const accountInfo = Account.parse(new Uint8Array(accountInformation));
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
epoch: accountInfo.epoch,
|
|
36
|
+
open_orders: accountInfo.open_orders,
|
|
37
|
+
taker_volume: Number(accountInfo.taker_volume) / baseScalar,
|
|
38
|
+
maker_volume: Number(accountInfo.maker_volume) / baseScalar,
|
|
39
|
+
active_stake: Number(accountInfo.active_stake) / DEEP_SCALAR,
|
|
40
|
+
inactive_stake: Number(accountInfo.inactive_stake) / DEEP_SCALAR,
|
|
41
|
+
created_proposal: accountInfo.created_proposal,
|
|
42
|
+
voted_proposal: accountInfo.voted_proposal,
|
|
43
|
+
unclaimed_rebates: {
|
|
44
|
+
base: Number(accountInfo.unclaimed_rebates.base) / baseScalar,
|
|
45
|
+
quote: Number(accountInfo.unclaimed_rebates.quote) / quoteScalar,
|
|
46
|
+
deep: Number(accountInfo.unclaimed_rebates.deep) / DEEP_SCALAR,
|
|
47
|
+
},
|
|
48
|
+
settled_balances: {
|
|
49
|
+
base: Number(accountInfo.settled_balances.base) / baseScalar,
|
|
50
|
+
quote: Number(accountInfo.settled_balances.quote) / quoteScalar,
|
|
51
|
+
deep: Number(accountInfo.settled_balances.deep) / DEEP_SCALAR,
|
|
52
|
+
},
|
|
53
|
+
owed_balances: {
|
|
54
|
+
base: Number(accountInfo.owed_balances.base) / baseScalar,
|
|
55
|
+
quote: Number(accountInfo.owed_balances.quote) / quoteScalar,
|
|
56
|
+
deep: Number(accountInfo.owed_balances.deep) / DEEP_SCALAR,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async lockedBalance(poolKey: string, balanceManagerKey: string): Promise<LockedBalances> {
|
|
62
|
+
const tx = new Transaction();
|
|
63
|
+
const pool = this.#ctx.config.getPool(poolKey);
|
|
64
|
+
const baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;
|
|
65
|
+
const quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;
|
|
66
|
+
|
|
67
|
+
tx.add(this.#ctx.deepBook.lockedBalance(poolKey, balanceManagerKey));
|
|
68
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
69
|
+
transaction: tx,
|
|
70
|
+
include: { commandResults: true, effects: true },
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const baseLocked = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));
|
|
74
|
+
const quoteLocked = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));
|
|
75
|
+
const deepLocked = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
base: Number((baseLocked / baseScalar).toFixed(9)),
|
|
79
|
+
quote: Number((quoteLocked / quoteScalar).toFixed(9)),
|
|
80
|
+
deep: Number((deepLocked / DEEP_SCALAR).toFixed(9)),
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
async getPoolDeepPrice(poolKey: string): Promise<PoolDeepPrice> {
|
|
85
|
+
const tx = new Transaction();
|
|
86
|
+
const pool = this.#ctx.config.getPool(poolKey);
|
|
87
|
+
tx.add(this.#ctx.deepBook.getPoolDeepPrice(poolKey));
|
|
88
|
+
|
|
89
|
+
const baseCoin = this.#ctx.config.getCoin(pool.baseCoin);
|
|
90
|
+
const quoteCoin = this.#ctx.config.getCoin(pool.quoteCoin);
|
|
91
|
+
const deepCoin = this.#ctx.config.getCoin('DEEP');
|
|
92
|
+
|
|
93
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
94
|
+
transaction: tx,
|
|
95
|
+
include: { commandResults: true, effects: true },
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const poolDeepPriceBytes = res.commandResults![0].returnValues[0].bcs;
|
|
99
|
+
const poolDeepPrice = OrderDeepPrice.parse(new Uint8Array(poolDeepPriceBytes));
|
|
100
|
+
|
|
101
|
+
if (poolDeepPrice.asset_is_base) {
|
|
102
|
+
return {
|
|
103
|
+
asset_is_base: poolDeepPrice.asset_is_base,
|
|
104
|
+
deep_per_base:
|
|
105
|
+
((Number(poolDeepPrice.deep_per_asset) / FLOAT_SCALAR) * baseCoin.scalar) /
|
|
106
|
+
deepCoin.scalar,
|
|
107
|
+
};
|
|
108
|
+
} else {
|
|
109
|
+
return {
|
|
110
|
+
asset_is_base: poolDeepPrice.asset_is_base,
|
|
111
|
+
deep_per_quote:
|
|
112
|
+
((Number(poolDeepPrice.deep_per_asset) / FLOAT_SCALAR) * quoteCoin.scalar) /
|
|
113
|
+
deepCoin.scalar,
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { bcs } from '@mysten/sui/bcs';
|
|
5
|
+
import { Transaction } from '@mysten/sui/transactions';
|
|
6
|
+
import { normalizeSuiAddress } from '@mysten/sui/utils';
|
|
7
|
+
|
|
8
|
+
import type { ManagerBalance } from '../types/index.js';
|
|
9
|
+
import type { QueryContext } from './context.js';
|
|
10
|
+
|
|
11
|
+
export class BalanceManagerQueries {
|
|
12
|
+
#ctx: QueryContext;
|
|
13
|
+
|
|
14
|
+
constructor(ctx: QueryContext) {
|
|
15
|
+
this.#ctx = ctx;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async checkManagerBalance(managerKey: string, coinKey: string): Promise<ManagerBalance> {
|
|
19
|
+
const tx = new Transaction();
|
|
20
|
+
const coin = this.#ctx.config.getCoin(coinKey);
|
|
21
|
+
|
|
22
|
+
tx.add(this.#ctx.balanceManager.checkManagerBalance(managerKey, coinKey));
|
|
23
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
24
|
+
transaction: tx,
|
|
25
|
+
include: { commandResults: true, effects: true },
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
29
|
+
const parsed_balance = bcs.U64.parse(bytes);
|
|
30
|
+
const balanceNumber = Number(parsed_balance);
|
|
31
|
+
const adjusted_balance = balanceNumber / coin.scalar;
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
coinType: coin.type,
|
|
35
|
+
balance: Number(adjusted_balance.toFixed(9)),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async checkManagerBalanceWithAddress(
|
|
40
|
+
managerAddress: string,
|
|
41
|
+
coinKey: string,
|
|
42
|
+
): Promise<ManagerBalance> {
|
|
43
|
+
const tx = new Transaction();
|
|
44
|
+
const coin = this.#ctx.config.getCoin(coinKey);
|
|
45
|
+
|
|
46
|
+
tx.moveCall({
|
|
47
|
+
target: `${this.#ctx.config.DEEPBOOK_PACKAGE_ID}::balance_manager::balance`,
|
|
48
|
+
arguments: [tx.object(managerAddress)],
|
|
49
|
+
typeArguments: [coin.type],
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
53
|
+
transaction: tx,
|
|
54
|
+
include: { commandResults: true, effects: true },
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
58
|
+
const parsed_balance = bcs.U64.parse(bytes);
|
|
59
|
+
const balanceNumber = Number(parsed_balance);
|
|
60
|
+
const adjusted_balance = balanceNumber / coin.scalar;
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
coinType: coin.type,
|
|
64
|
+
balance: Number(adjusted_balance.toFixed(9)),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async checkManagerBalancesWithAddress(
|
|
69
|
+
managerAddresses: string[],
|
|
70
|
+
coinKeys: string[],
|
|
71
|
+
): Promise<Record<string, Record<string, number>>> {
|
|
72
|
+
if (managerAddresses.length === 0 || coinKeys.length === 0) {
|
|
73
|
+
return {};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const tx = new Transaction();
|
|
77
|
+
const coins = coinKeys.map((coinKey) => this.#ctx.config.getCoin(coinKey));
|
|
78
|
+
|
|
79
|
+
for (const managerAddress of managerAddresses) {
|
|
80
|
+
for (const coin of coins) {
|
|
81
|
+
tx.moveCall({
|
|
82
|
+
target: `${this.#ctx.config.DEEPBOOK_PACKAGE_ID}::balance_manager::balance`,
|
|
83
|
+
arguments: [tx.object(managerAddress)],
|
|
84
|
+
typeArguments: [coin.type],
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
90
|
+
transaction: tx,
|
|
91
|
+
include: { commandResults: true, effects: true },
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
if (res.FailedTransaction) {
|
|
95
|
+
throw new Error(
|
|
96
|
+
`Transaction failed: ${res.FailedTransaction.status.error?.message || 'Unknown error'}`,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (!res.commandResults) {
|
|
101
|
+
throw new Error('Failed to get manager balances: No command results');
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const results: Record<string, Record<string, number>> = {};
|
|
105
|
+
|
|
106
|
+
for (let m = 0; m < managerAddresses.length; m++) {
|
|
107
|
+
const managerAddress = managerAddresses[m];
|
|
108
|
+
const managerBalances: Record<string, number> = {};
|
|
109
|
+
|
|
110
|
+
for (let c = 0; c < coins.length; c++) {
|
|
111
|
+
const coin = coins[c];
|
|
112
|
+
const commandResult = res.commandResults[m * coins.length + c];
|
|
113
|
+
|
|
114
|
+
if (!commandResult || !commandResult.returnValues) {
|
|
115
|
+
throw new Error(`Failed to get balance for ${coin.type}: No return values`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const bytes = commandResult.returnValues[0].bcs;
|
|
119
|
+
const parsed_balance = bcs.U64.parse(bytes);
|
|
120
|
+
managerBalances[coin.type] = Number((Number(parsed_balance) / coin.scalar).toFixed(9));
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
results[managerAddress] = managerBalances;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return results;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
async getBalanceManagerIds(owner: string): Promise<string[]> {
|
|
130
|
+
const tx = new Transaction();
|
|
131
|
+
tx.add(this.#ctx.deepBook.getBalanceManagerIds(owner));
|
|
132
|
+
|
|
133
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
134
|
+
transaction: tx,
|
|
135
|
+
include: { commandResults: true, effects: true },
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
139
|
+
const vecOfAddresses = bcs.vector(bcs.Address).parse(bytes);
|
|
140
|
+
|
|
141
|
+
return vecOfAddresses.map((id: string) => normalizeSuiAddress(id));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
async accountExists(poolKey: string, managerKey: string): Promise<boolean> {
|
|
145
|
+
const tx = new Transaction();
|
|
146
|
+
tx.add(this.#ctx.deepBook.accountExists(poolKey, managerKey));
|
|
147
|
+
|
|
148
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
149
|
+
transaction: tx,
|
|
150
|
+
include: { commandResults: true, effects: true },
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
const bytes = res.commandResults![0].returnValues[0].bcs;
|
|
154
|
+
return bcs.bool().parse(bytes);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { DeepBookCompatibleClient } from '../client.js';
|
|
5
|
+
import type { BalanceManagerContract } from '../transactions/balanceManager.js';
|
|
6
|
+
import type { DeepBookContract } from '../transactions/deepbook.js';
|
|
7
|
+
import type { MarginManagerContract } from '../transactions/marginManager.js';
|
|
8
|
+
import type { MarginPoolContract } from '../transactions/marginPool.js';
|
|
9
|
+
import type { MarginRegistryContract } from '../transactions/marginRegistry.js';
|
|
10
|
+
import type { MarginTPSLContract } from '../transactions/marginTPSL.js';
|
|
11
|
+
import type { DeepBookConfig } from '../utils/config.js';
|
|
12
|
+
|
|
13
|
+
export interface QueryContext {
|
|
14
|
+
client: DeepBookCompatibleClient;
|
|
15
|
+
config: DeepBookConfig;
|
|
16
|
+
address: string;
|
|
17
|
+
balanceManager: BalanceManagerContract;
|
|
18
|
+
deepBook: DeepBookContract;
|
|
19
|
+
marginManager: MarginManagerContract;
|
|
20
|
+
marginPool: MarginPoolContract;
|
|
21
|
+
marginRegistry: MarginRegistryContract;
|
|
22
|
+
marginTPSL: MarginTPSLContract;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function formatTokenAmount(rawAmount: bigint, scalar: number, decimals: number): string {
|
|
26
|
+
const scalarBigInt = BigInt(scalar);
|
|
27
|
+
const integerPart = rawAmount / scalarBigInt;
|
|
28
|
+
const fractionalPart = rawAmount % scalarBigInt;
|
|
29
|
+
|
|
30
|
+
if (fractionalPart === 0n) {
|
|
31
|
+
return integerPart.toString();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const scalarDigits = scalar.toString().length - 1;
|
|
35
|
+
const fractionalStr = fractionalPart.toString().padStart(scalarDigits, '0');
|
|
36
|
+
const truncated = fractionalStr.slice(0, decimals);
|
|
37
|
+
const trimmed = truncated.replace(/0+$/, '');
|
|
38
|
+
|
|
39
|
+
if (!trimmed) {
|
|
40
|
+
return integerPart.toString();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return `${integerPart}.${trimmed}`;
|
|
44
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export { formatTokenAmount } from './context.js';
|
|
5
|
+
export type { QueryContext } from './context.js';
|
|
6
|
+
export { AccountQueries } from './accountQueries.js';
|
|
7
|
+
export { BalanceManagerQueries } from './balanceManagerQueries.js';
|
|
8
|
+
export { MarginManagerQueries } from './marginManagerQueries.js';
|
|
9
|
+
export { MarginPoolQueries } from './marginPoolQueries.js';
|
|
10
|
+
export { OrderQueries } from './orderQueries.js';
|
|
11
|
+
export { PoolQueries } from './poolQueries.js';
|
|
12
|
+
export { PriceFeedQueries } from './priceFeedQueries.js';
|
|
13
|
+
export { QuantityQueries } from './quantityQueries.js';
|
|
14
|
+
export { ReferralQueries } from './referralQueries.js';
|
|
15
|
+
export { RegistryQueries } from './registryQueries.js';
|
|
16
|
+
export { TPSLQueries } from './tpslQueries.js';
|