@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
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
import { DEEP_SCALAR, FLOAT_SCALAR } from "../utils/config.mjs";
|
|
2
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
3
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
4
|
+
import { normalizeSuiAddress } from "@mysten/sui/utils";
|
|
5
|
+
|
|
6
|
+
//#region src/queries/poolQueries.ts
|
|
7
|
+
var PoolQueries = class {
|
|
8
|
+
#ctx;
|
|
9
|
+
constructor(ctx) {
|
|
10
|
+
this.#ctx = ctx;
|
|
11
|
+
}
|
|
12
|
+
async whitelisted(poolKey) {
|
|
13
|
+
const tx = new Transaction();
|
|
14
|
+
tx.add(this.#ctx.deepBook.whitelisted(poolKey));
|
|
15
|
+
const bytes = (await this.#ctx.client.core.simulateTransaction({
|
|
16
|
+
transaction: tx,
|
|
17
|
+
include: {
|
|
18
|
+
commandResults: true,
|
|
19
|
+
effects: true
|
|
20
|
+
}
|
|
21
|
+
})).commandResults[0].returnValues[0].bcs;
|
|
22
|
+
return bcs.Bool.parse(bytes);
|
|
23
|
+
}
|
|
24
|
+
async vaultBalances(poolKey) {
|
|
25
|
+
const tx = new Transaction();
|
|
26
|
+
const pool = this.#ctx.config.getPool(poolKey);
|
|
27
|
+
const baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;
|
|
28
|
+
const quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;
|
|
29
|
+
tx.add(this.#ctx.deepBook.vaultBalances(poolKey));
|
|
30
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
31
|
+
transaction: tx,
|
|
32
|
+
include: {
|
|
33
|
+
commandResults: true,
|
|
34
|
+
effects: true
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
const baseInVault = Number(bcs.U64.parse(res.commandResults[0].returnValues[0].bcs));
|
|
38
|
+
const quoteInVault = Number(bcs.U64.parse(res.commandResults[0].returnValues[1].bcs));
|
|
39
|
+
const deepInVault = Number(bcs.U64.parse(res.commandResults[0].returnValues[2].bcs));
|
|
40
|
+
return {
|
|
41
|
+
base: Number((baseInVault / baseScalar).toFixed(9)),
|
|
42
|
+
quote: Number((quoteInVault / quoteScalar).toFixed(9)),
|
|
43
|
+
deep: Number((deepInVault / DEEP_SCALAR).toFixed(9))
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
async getPoolIdByAssets(baseType, quoteType) {
|
|
47
|
+
const tx = new Transaction();
|
|
48
|
+
tx.add(this.#ctx.deepBook.getPoolIdByAssets(baseType, quoteType));
|
|
49
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
50
|
+
transaction: tx,
|
|
51
|
+
include: {
|
|
52
|
+
commandResults: true,
|
|
53
|
+
effects: true
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
return bcs.Address.parse(res.commandResults[0].returnValues[0].bcs);
|
|
57
|
+
}
|
|
58
|
+
async midPrice(poolKey) {
|
|
59
|
+
const tx = new Transaction();
|
|
60
|
+
const pool = this.#ctx.config.getPool(poolKey);
|
|
61
|
+
tx.add(this.#ctx.deepBook.midPrice(poolKey));
|
|
62
|
+
const baseCoin = this.#ctx.config.getCoin(pool.baseCoin);
|
|
63
|
+
const quoteCoin = this.#ctx.config.getCoin(pool.quoteCoin);
|
|
64
|
+
const bytes = (await this.#ctx.client.core.simulateTransaction({
|
|
65
|
+
transaction: tx,
|
|
66
|
+
include: {
|
|
67
|
+
commandResults: true,
|
|
68
|
+
effects: true
|
|
69
|
+
}
|
|
70
|
+
})).commandResults[0].returnValues[0].bcs;
|
|
71
|
+
const adjusted_mid_price = Number(bcs.U64.parse(bytes)) * baseCoin.scalar / quoteCoin.scalar / FLOAT_SCALAR;
|
|
72
|
+
return Number(adjusted_mid_price.toFixed(9));
|
|
73
|
+
}
|
|
74
|
+
async poolTradeParams(poolKey) {
|
|
75
|
+
const tx = new Transaction();
|
|
76
|
+
tx.add(this.#ctx.deepBook.poolTradeParams(poolKey));
|
|
77
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
78
|
+
transaction: tx,
|
|
79
|
+
include: {
|
|
80
|
+
commandResults: true,
|
|
81
|
+
effects: true
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
const takerFee = Number(bcs.U64.parse(res.commandResults[0].returnValues[0].bcs));
|
|
85
|
+
const makerFee = Number(bcs.U64.parse(res.commandResults[0].returnValues[1].bcs));
|
|
86
|
+
const stakeRequired = Number(bcs.U64.parse(res.commandResults[0].returnValues[2].bcs));
|
|
87
|
+
return {
|
|
88
|
+
takerFee: Number(takerFee / FLOAT_SCALAR),
|
|
89
|
+
makerFee: Number(makerFee / FLOAT_SCALAR),
|
|
90
|
+
stakeRequired: Number(stakeRequired / DEEP_SCALAR)
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
async poolBookParams(poolKey) {
|
|
94
|
+
const tx = new Transaction();
|
|
95
|
+
const pool = this.#ctx.config.getPool(poolKey);
|
|
96
|
+
const baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;
|
|
97
|
+
const quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;
|
|
98
|
+
tx.add(this.#ctx.deepBook.poolBookParams(poolKey));
|
|
99
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
100
|
+
transaction: tx,
|
|
101
|
+
include: {
|
|
102
|
+
commandResults: true,
|
|
103
|
+
effects: true
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
const tickSize = Number(bcs.U64.parse(res.commandResults[0].returnValues[0].bcs));
|
|
107
|
+
const lotSize = Number(bcs.U64.parse(res.commandResults[0].returnValues[1].bcs));
|
|
108
|
+
const minSize = Number(bcs.U64.parse(res.commandResults[0].returnValues[2].bcs));
|
|
109
|
+
return {
|
|
110
|
+
tickSize: Number(tickSize * baseScalar / quoteScalar / FLOAT_SCALAR),
|
|
111
|
+
lotSize: Number(lotSize / baseScalar),
|
|
112
|
+
minSize: Number(minSize / baseScalar)
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
async stablePool(poolKey) {
|
|
116
|
+
const tx = new Transaction();
|
|
117
|
+
tx.add(this.#ctx.deepBook.stablePool(poolKey));
|
|
118
|
+
const bytes = (await this.#ctx.client.core.simulateTransaction({
|
|
119
|
+
transaction: tx,
|
|
120
|
+
include: {
|
|
121
|
+
commandResults: true,
|
|
122
|
+
effects: true
|
|
123
|
+
}
|
|
124
|
+
})).commandResults[0].returnValues[0].bcs;
|
|
125
|
+
return bcs.bool().parse(bytes);
|
|
126
|
+
}
|
|
127
|
+
async registeredPool(poolKey) {
|
|
128
|
+
const tx = new Transaction();
|
|
129
|
+
tx.add(this.#ctx.deepBook.registeredPool(poolKey));
|
|
130
|
+
const bytes = (await this.#ctx.client.core.simulateTransaction({
|
|
131
|
+
transaction: tx,
|
|
132
|
+
include: {
|
|
133
|
+
commandResults: true,
|
|
134
|
+
effects: true
|
|
135
|
+
}
|
|
136
|
+
})).commandResults[0].returnValues[0].bcs;
|
|
137
|
+
return bcs.bool().parse(bytes);
|
|
138
|
+
}
|
|
139
|
+
async poolTradeParamsNext(poolKey) {
|
|
140
|
+
const tx = new Transaction();
|
|
141
|
+
tx.add(this.#ctx.deepBook.poolTradeParamsNext(poolKey));
|
|
142
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
143
|
+
transaction: tx,
|
|
144
|
+
include: {
|
|
145
|
+
commandResults: true,
|
|
146
|
+
effects: true
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
const takerFee = Number(bcs.U64.parse(res.commandResults[0].returnValues[0].bcs));
|
|
150
|
+
const makerFee = Number(bcs.U64.parse(res.commandResults[0].returnValues[1].bcs));
|
|
151
|
+
const stakeRequired = Number(bcs.U64.parse(res.commandResults[0].returnValues[2].bcs));
|
|
152
|
+
return {
|
|
153
|
+
takerFee: takerFee / FLOAT_SCALAR,
|
|
154
|
+
makerFee: makerFee / FLOAT_SCALAR,
|
|
155
|
+
stakeRequired: stakeRequired / DEEP_SCALAR
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
async quorum(poolKey) {
|
|
159
|
+
const tx = new Transaction();
|
|
160
|
+
tx.add(this.#ctx.deepBook.quorum(poolKey));
|
|
161
|
+
const bytes = (await this.#ctx.client.core.simulateTransaction({
|
|
162
|
+
transaction: tx,
|
|
163
|
+
include: {
|
|
164
|
+
commandResults: true,
|
|
165
|
+
effects: true
|
|
166
|
+
}
|
|
167
|
+
})).commandResults[0].returnValues[0].bcs;
|
|
168
|
+
return Number(bcs.U64.parse(bytes)) / DEEP_SCALAR;
|
|
169
|
+
}
|
|
170
|
+
async poolId(poolKey) {
|
|
171
|
+
const tx = new Transaction();
|
|
172
|
+
tx.add(this.#ctx.deepBook.poolId(poolKey));
|
|
173
|
+
const bytes = (await this.#ctx.client.core.simulateTransaction({
|
|
174
|
+
transaction: tx,
|
|
175
|
+
include: {
|
|
176
|
+
commandResults: true,
|
|
177
|
+
effects: true
|
|
178
|
+
}
|
|
179
|
+
})).commandResults[0].returnValues[0].bcs;
|
|
180
|
+
return normalizeSuiAddress(bcs.Address.parse(bytes));
|
|
181
|
+
}
|
|
182
|
+
async canPlaceLimitOrder(params) {
|
|
183
|
+
const tx = new Transaction();
|
|
184
|
+
tx.add(this.#ctx.deepBook.canPlaceLimitOrder(params));
|
|
185
|
+
const bytes = (await this.#ctx.client.core.simulateTransaction({
|
|
186
|
+
transaction: tx,
|
|
187
|
+
include: {
|
|
188
|
+
commandResults: true,
|
|
189
|
+
effects: true
|
|
190
|
+
}
|
|
191
|
+
})).commandResults[0].returnValues[0].bcs;
|
|
192
|
+
return bcs.bool().parse(bytes);
|
|
193
|
+
}
|
|
194
|
+
async canPlaceMarketOrder(params) {
|
|
195
|
+
const tx = new Transaction();
|
|
196
|
+
tx.add(this.#ctx.deepBook.canPlaceMarketOrder(params));
|
|
197
|
+
const bytes = (await this.#ctx.client.core.simulateTransaction({
|
|
198
|
+
transaction: tx,
|
|
199
|
+
include: {
|
|
200
|
+
commandResults: true,
|
|
201
|
+
effects: true
|
|
202
|
+
}
|
|
203
|
+
})).commandResults[0].returnValues[0].bcs;
|
|
204
|
+
return bcs.bool().parse(bytes);
|
|
205
|
+
}
|
|
206
|
+
async checkMarketOrderParams(poolKey, quantity) {
|
|
207
|
+
const tx = new Transaction();
|
|
208
|
+
tx.add(this.#ctx.deepBook.checkMarketOrderParams(poolKey, quantity));
|
|
209
|
+
const bytes = (await this.#ctx.client.core.simulateTransaction({
|
|
210
|
+
transaction: tx,
|
|
211
|
+
include: {
|
|
212
|
+
commandResults: true,
|
|
213
|
+
effects: true
|
|
214
|
+
}
|
|
215
|
+
})).commandResults[0].returnValues[0].bcs;
|
|
216
|
+
return bcs.bool().parse(bytes);
|
|
217
|
+
}
|
|
218
|
+
async checkLimitOrderParams(poolKey, price, quantity, expireTimestamp) {
|
|
219
|
+
const tx = new Transaction();
|
|
220
|
+
tx.add(this.#ctx.deepBook.checkLimitOrderParams(poolKey, price, quantity, expireTimestamp));
|
|
221
|
+
const bytes = (await this.#ctx.client.core.simulateTransaction({
|
|
222
|
+
transaction: tx,
|
|
223
|
+
include: {
|
|
224
|
+
commandResults: true,
|
|
225
|
+
effects: true
|
|
226
|
+
}
|
|
227
|
+
})).commandResults[0].returnValues[0].bcs;
|
|
228
|
+
return bcs.bool().parse(bytes);
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
//#endregion
|
|
233
|
+
export { PoolQueries };
|
|
234
|
+
//# sourceMappingURL=poolQueries.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"poolQueries.mjs","names":["#ctx"],"sources":["../../src/queries/poolQueries.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '@mysten/sui/bcs';\nimport { Transaction } from '@mysten/sui/transactions';\nimport { normalizeSuiAddress } from '@mysten/sui/utils';\n\nimport type {\n\tCanPlaceLimitOrderParams,\n\tCanPlaceMarketOrderParams,\n\tPoolBookParams,\n\tPoolTradeParams,\n\tVaultBalances,\n} from '../types/index.js';\nimport { DEEP_SCALAR, FLOAT_SCALAR } from '../utils/config.js';\nimport type { QueryContext } from './context.js';\n\nexport class PoolQueries {\n\t#ctx: QueryContext;\n\n\tconstructor(ctx: QueryContext) {\n\t\tthis.#ctx = ctx;\n\t}\n\n\tasync whitelisted(poolKey: string): Promise<boolean> {\n\t\tconst tx = new Transaction();\n\n\t\ttx.add(this.#ctx.deepBook.whitelisted(poolKey));\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\treturn bcs.Bool.parse(bytes);\n\t}\n\n\tasync vaultBalances(poolKey: string): Promise<VaultBalances> {\n\t\tconst tx = new Transaction();\n\t\tconst pool = this.#ctx.config.getPool(poolKey);\n\t\tconst baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;\n\t\tconst quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;\n\n\t\ttx.add(this.#ctx.deepBook.vaultBalances(poolKey));\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst baseInVault = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));\n\t\tconst quoteInVault = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));\n\t\tconst deepInVault = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));\n\n\t\treturn {\n\t\t\tbase: Number((baseInVault / baseScalar).toFixed(9)),\n\t\t\tquote: Number((quoteInVault / quoteScalar).toFixed(9)),\n\t\t\tdeep: Number((deepInVault / DEEP_SCALAR).toFixed(9)),\n\t\t};\n\t}\n\n\tasync getPoolIdByAssets(baseType: string, quoteType: string): Promise<string> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.deepBook.getPoolIdByAssets(baseType, quoteType));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\treturn bcs.Address.parse(res.commandResults![0].returnValues[0].bcs);\n\t}\n\n\tasync midPrice(poolKey: string): Promise<number> {\n\t\tconst tx = new Transaction();\n\t\tconst pool = this.#ctx.config.getPool(poolKey);\n\t\ttx.add(this.#ctx.deepBook.midPrice(poolKey));\n\n\t\tconst baseCoin = this.#ctx.config.getCoin(pool.baseCoin);\n\t\tconst quoteCoin = this.#ctx.config.getCoin(pool.quoteCoin);\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\tconst parsed_mid_price = Number(bcs.U64.parse(bytes));\n\t\tconst adjusted_mid_price =\n\t\t\t(parsed_mid_price * baseCoin.scalar) / quoteCoin.scalar / FLOAT_SCALAR;\n\n\t\treturn Number(adjusted_mid_price.toFixed(9));\n\t}\n\n\tasync poolTradeParams(poolKey: string): Promise<PoolTradeParams> {\n\t\tconst tx = new Transaction();\n\n\t\ttx.add(this.#ctx.deepBook.poolTradeParams(poolKey));\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst takerFee = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));\n\t\tconst makerFee = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));\n\t\tconst stakeRequired = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));\n\n\t\treturn {\n\t\t\ttakerFee: Number(takerFee / FLOAT_SCALAR),\n\t\t\tmakerFee: Number(makerFee / FLOAT_SCALAR),\n\t\t\tstakeRequired: Number(stakeRequired / DEEP_SCALAR),\n\t\t};\n\t}\n\n\tasync poolBookParams(poolKey: string): Promise<PoolBookParams> {\n\t\tconst tx = new Transaction();\n\t\tconst pool = this.#ctx.config.getPool(poolKey);\n\t\tconst baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;\n\t\tconst quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;\n\n\t\ttx.add(this.#ctx.deepBook.poolBookParams(poolKey));\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst tickSize = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));\n\t\tconst lotSize = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));\n\t\tconst minSize = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));\n\n\t\treturn {\n\t\t\ttickSize: Number((tickSize * baseScalar) / quoteScalar / FLOAT_SCALAR),\n\t\t\tlotSize: Number(lotSize / baseScalar),\n\t\t\tminSize: Number(minSize / baseScalar),\n\t\t};\n\t}\n\n\tasync stablePool(poolKey: string): Promise<boolean> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.deepBook.stablePool(poolKey));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\treturn bcs.bool().parse(bytes);\n\t}\n\n\tasync registeredPool(poolKey: string): Promise<boolean> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.deepBook.registeredPool(poolKey));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\treturn bcs.bool().parse(bytes);\n\t}\n\n\tasync poolTradeParamsNext(poolKey: string): Promise<PoolTradeParams> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.deepBook.poolTradeParamsNext(poolKey));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst takerFee = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));\n\t\tconst makerFee = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));\n\t\tconst stakeRequired = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));\n\n\t\treturn {\n\t\t\ttakerFee: takerFee / FLOAT_SCALAR,\n\t\t\tmakerFee: makerFee / FLOAT_SCALAR,\n\t\t\tstakeRequired: stakeRequired / DEEP_SCALAR,\n\t\t};\n\t}\n\n\tasync quorum(poolKey: string): Promise<number> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.deepBook.quorum(poolKey));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\tconst quorum = Number(bcs.U64.parse(bytes));\n\t\treturn quorum / DEEP_SCALAR;\n\t}\n\n\tasync poolId(poolKey: string): Promise<string> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.deepBook.poolId(poolKey));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\treturn normalizeSuiAddress(bcs.Address.parse(bytes));\n\t}\n\n\tasync canPlaceLimitOrder(params: CanPlaceLimitOrderParams): Promise<boolean> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.deepBook.canPlaceLimitOrder(params));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\treturn bcs.bool().parse(bytes);\n\t}\n\n\tasync canPlaceMarketOrder(params: CanPlaceMarketOrderParams): Promise<boolean> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.deepBook.canPlaceMarketOrder(params));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\treturn bcs.bool().parse(bytes);\n\t}\n\n\tasync checkMarketOrderParams(poolKey: string, quantity: number | bigint): Promise<boolean> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.deepBook.checkMarketOrderParams(poolKey, quantity));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\treturn bcs.bool().parse(bytes);\n\t}\n\n\tasync checkLimitOrderParams(\n\t\tpoolKey: string,\n\t\tprice: number | bigint,\n\t\tquantity: number | bigint,\n\t\texpireTimestamp: number,\n\t): Promise<boolean> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.deepBook.checkLimitOrderParams(poolKey, price, quantity, expireTimestamp));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst bytes = res.commandResults![0].returnValues[0].bcs;\n\t\treturn bcs.bool().parse(bytes);\n\t}\n}\n"],"mappings":";;;;;;AAiBA,IAAa,cAAb,MAAyB;CACxB;CAEA,YAAY,KAAmB;AAC9B,QAAKA,MAAO;;CAGb,MAAM,YAAY,SAAmC;EACpD,MAAM,KAAK,IAAI,aAAa;AAE5B,KAAG,IAAI,MAAKA,IAAK,SAAS,YAAY,QAAQ,CAAC;EAM/C,MAAM,SALM,MAAM,MAAKA,IAAK,OAAO,KAAK,oBAAoB;GAC3D,aAAa;GACb,SAAS;IAAE,gBAAgB;IAAM,SAAS;IAAM;GAChD,CAA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C5B,KAAG,IAAI,MAAKA,IAAK,SAAS,sBAAsB,SAAS,OAAO,UAAU,gBAAgB,CAAC;EAO3F,MAAM,SALM,MAAM,MAAKA,IAAK,OAAO,KAAK,oBAAoB;GAC3D,aAAa;GACb,SAAS;IAAE,gBAAgB;IAAM,SAAS;IAAM;GAChD,CAAC,EAEgB,eAAgB,GAAG,aAAa,GAAG;AACrD,SAAO,IAAI,MAAM,CAAC,MAAM,MAAM"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { PRICE_INFO_OBJECT_MAX_AGE_MS } from "../utils/config.mjs";
|
|
2
|
+
import { PriceInfoObject } from "../contracts/pyth/price_info.mjs";
|
|
3
|
+
import { SuiPriceServiceConnection, SuiPythClient } from "../pyth/pyth.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/queries/priceFeedQueries.ts
|
|
6
|
+
var PriceFeedQueries = class {
|
|
7
|
+
#ctx;
|
|
8
|
+
constructor(ctx) {
|
|
9
|
+
this.#ctx = ctx;
|
|
10
|
+
}
|
|
11
|
+
async getPriceInfoObject(tx, coinKey) {
|
|
12
|
+
this.#ctx.config.requirePyth();
|
|
13
|
+
const currentTime = Date.now();
|
|
14
|
+
const priceInfoObjectAge = await this.getPriceInfoObjectAge(coinKey);
|
|
15
|
+
if (priceInfoObjectAge && currentTime - priceInfoObjectAge * 1e3 < PRICE_INFO_OBJECT_MAX_AGE_MS) return await this.#ctx.config.getCoin(coinKey).priceInfoObjectId;
|
|
16
|
+
const connection = new SuiPriceServiceConnection(this.#ctx.config.network === "testnet" ? "https://hermes-beta.pyth.network" : "https://hermes.pyth.network");
|
|
17
|
+
const priceIDs = [this.#ctx.config.getCoin(coinKey).feed];
|
|
18
|
+
const priceUpdateData = await connection.getPriceFeedsUpdateData(priceIDs);
|
|
19
|
+
const wormholeStateId = this.#ctx.config.pyth.wormholeStateId;
|
|
20
|
+
const pythStateId = this.#ctx.config.pyth.pythStateId;
|
|
21
|
+
return (await new SuiPythClient(this.#ctx.client, pythStateId, wormholeStateId).updatePriceFeeds(tx, priceUpdateData, priceIDs))[0];
|
|
22
|
+
}
|
|
23
|
+
async getPriceInfoObjects(tx, coinKeys) {
|
|
24
|
+
this.#ctx.config.requirePyth();
|
|
25
|
+
if (coinKeys.length === 0) return {};
|
|
26
|
+
const currentTime = Date.now();
|
|
27
|
+
const coinToObjectId = {};
|
|
28
|
+
const objectIds = [];
|
|
29
|
+
for (const coinKey of coinKeys) {
|
|
30
|
+
const priceInfoObjectId = this.#ctx.config.getCoin(coinKey).priceInfoObjectId;
|
|
31
|
+
coinToObjectId[coinKey] = priceInfoObjectId;
|
|
32
|
+
objectIds.push(priceInfoObjectId);
|
|
33
|
+
}
|
|
34
|
+
const res = await this.#ctx.client.core.getObjects({
|
|
35
|
+
objectIds,
|
|
36
|
+
include: { content: true }
|
|
37
|
+
});
|
|
38
|
+
const staleCoinKeys = [];
|
|
39
|
+
const result = {};
|
|
40
|
+
for (let i = 0; i < coinKeys.length; i++) {
|
|
41
|
+
const coinKey = coinKeys[i];
|
|
42
|
+
const obj = res.objects[i];
|
|
43
|
+
if (obj instanceof Error || !obj?.content) {
|
|
44
|
+
staleCoinKeys.push(coinKey);
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
const priceInfoObject = PriceInfoObject.parse(obj.content);
|
|
48
|
+
if (currentTime - Number(priceInfoObject.price_info.arrival_time) * 1e3 >= PRICE_INFO_OBJECT_MAX_AGE_MS) staleCoinKeys.push(coinKey);
|
|
49
|
+
else result[coinKey] = coinToObjectId[coinKey];
|
|
50
|
+
}
|
|
51
|
+
if (staleCoinKeys.length === 0) return result;
|
|
52
|
+
const staleFeedIds = [];
|
|
53
|
+
const feedIdToCoinKey = {};
|
|
54
|
+
for (const coinKey of staleCoinKeys) {
|
|
55
|
+
const feedId = this.#ctx.config.getCoin(coinKey).feed;
|
|
56
|
+
staleFeedIds.push(feedId);
|
|
57
|
+
feedIdToCoinKey[feedId] = coinKey;
|
|
58
|
+
}
|
|
59
|
+
const priceUpdateData = await new SuiPriceServiceConnection(this.#ctx.config.network === "testnet" ? "https://hermes-beta.pyth.network" : "https://hermes.pyth.network").getPriceFeedsUpdateData(staleFeedIds);
|
|
60
|
+
const wormholeStateId = this.#ctx.config.pyth.wormholeStateId;
|
|
61
|
+
const pythStateId = this.#ctx.config.pyth.pythStateId;
|
|
62
|
+
const updatedObjectIds = await new SuiPythClient(this.#ctx.client, pythStateId, wormholeStateId).updatePriceFeeds(tx, priceUpdateData, staleFeedIds);
|
|
63
|
+
for (let i = 0; i < staleFeedIds.length; i++) {
|
|
64
|
+
const coinKey = feedIdToCoinKey[staleFeedIds[i]];
|
|
65
|
+
result[coinKey] = updatedObjectIds[i];
|
|
66
|
+
}
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
async getPriceInfoObjectAge(coinKey) {
|
|
70
|
+
const priceInfoObjectId = this.#ctx.config.getCoin(coinKey).priceInfoObjectId;
|
|
71
|
+
const res = await this.#ctx.client.core.getObject({
|
|
72
|
+
objectId: priceInfoObjectId,
|
|
73
|
+
include: { content: true }
|
|
74
|
+
});
|
|
75
|
+
if (!res.object?.content) throw new Error(`Price info object not found for ${coinKey}`);
|
|
76
|
+
const priceInfoObject = PriceInfoObject.parse(res.object.content);
|
|
77
|
+
return Number(priceInfoObject.price_info.arrival_time);
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
//#endregion
|
|
82
|
+
export { PriceFeedQueries };
|
|
83
|
+
//# sourceMappingURL=priceFeedQueries.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"priceFeedQueries.mjs","names":["#ctx"],"sources":["../../src/queries/priceFeedQueries.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Transaction } from '@mysten/sui/transactions';\n\nimport { PriceInfoObject } from '../contracts/pyth/price_info.js';\nimport { SuiPriceServiceConnection, SuiPythClient } from '../pyth/pyth.js';\nimport { PRICE_INFO_OBJECT_MAX_AGE_MS } from '../utils/config.js';\nimport type { QueryContext } from './context.js';\n\nexport class PriceFeedQueries {\n\t#ctx: QueryContext;\n\n\tconstructor(ctx: QueryContext) {\n\t\tthis.#ctx = ctx;\n\t}\n\n\tasync getPriceInfoObject(tx: Transaction, coinKey: string): Promise<string> {\n\t\tthis.#ctx.config.requirePyth();\n\t\tconst currentTime = Date.now();\n\t\tconst priceInfoObjectAge = await this.getPriceInfoObjectAge(coinKey);\n\t\tif (\n\t\t\tpriceInfoObjectAge &&\n\t\t\tcurrentTime - priceInfoObjectAge * 1000 < PRICE_INFO_OBJECT_MAX_AGE_MS\n\t\t) {\n\t\t\treturn await this.#ctx.config.getCoin(coinKey).priceInfoObjectId!;\n\t\t}\n\n\t\tconst endpoint =\n\t\t\tthis.#ctx.config.network === 'testnet'\n\t\t\t\t? 'https://hermes-beta.pyth.network'\n\t\t\t\t: 'https://hermes.pyth.network';\n\t\tconst connection = new SuiPriceServiceConnection(endpoint);\n\n\t\tconst priceIDs = [this.#ctx.config.getCoin(coinKey).feed!];\n\n\t\tconst priceUpdateData = await connection.getPriceFeedsUpdateData(priceIDs);\n\n\t\tconst wormholeStateId = this.#ctx.config.pyth.wormholeStateId;\n\t\tconst pythStateId = this.#ctx.config.pyth.pythStateId;\n\n\t\tconst client = new SuiPythClient(this.#ctx.client, pythStateId, wormholeStateId);\n\n\t\treturn (await client.updatePriceFeeds(tx, priceUpdateData, priceIDs))[0];\n\t}\n\n\tasync getPriceInfoObjects(tx: Transaction, coinKeys: string[]): Promise<Record<string, string>> {\n\t\tthis.#ctx.config.requirePyth();\n\t\tif (coinKeys.length === 0) {\n\t\t\treturn {};\n\t\t}\n\n\t\tconst currentTime = Date.now();\n\n\t\tconst coinToObjectId: Record<string, string> = {};\n\t\tconst objectIds: string[] = [];\n\t\tfor (const coinKey of coinKeys) {\n\t\t\tconst priceInfoObjectId = this.#ctx.config.getCoin(coinKey).priceInfoObjectId!;\n\t\t\tcoinToObjectId[coinKey] = priceInfoObjectId;\n\t\t\tobjectIds.push(priceInfoObjectId);\n\t\t}\n\n\t\tconst res = await this.#ctx.client.core.getObjects({\n\t\t\tobjectIds,\n\t\t\tinclude: { content: true },\n\t\t});\n\n\t\tconst staleCoinKeys: string[] = [];\n\t\tconst result: Record<string, string> = {};\n\n\t\tfor (let i = 0; i < coinKeys.length; i++) {\n\t\t\tconst coinKey = coinKeys[i];\n\t\t\tconst obj = res.objects[i];\n\n\t\t\tif (obj instanceof Error || !obj?.content) {\n\t\t\t\tstaleCoinKeys.push(coinKey);\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst priceInfoObject = PriceInfoObject.parse(obj.content);\n\t\t\tconst arrivalTime = Number(priceInfoObject.price_info.arrival_time);\n\t\t\tconst age = currentTime - arrivalTime * 1000;\n\n\t\t\tif (age >= PRICE_INFO_OBJECT_MAX_AGE_MS) {\n\t\t\t\tstaleCoinKeys.push(coinKey);\n\t\t\t} else {\n\t\t\t\tresult[coinKey] = coinToObjectId[coinKey];\n\t\t\t}\n\t\t}\n\n\t\tif (staleCoinKeys.length === 0) {\n\t\t\treturn result;\n\t\t}\n\n\t\tconst staleFeedIds: string[] = [];\n\t\tconst feedIdToCoinKey: Record<string, string> = {};\n\t\tfor (const coinKey of staleCoinKeys) {\n\t\t\tconst feedId = this.#ctx.config.getCoin(coinKey).feed!;\n\t\t\tstaleFeedIds.push(feedId);\n\t\t\tfeedIdToCoinKey[feedId] = coinKey;\n\t\t}\n\n\t\tconst endpoint =\n\t\t\tthis.#ctx.config.network === 'testnet'\n\t\t\t\t? 'https://hermes-beta.pyth.network'\n\t\t\t\t: 'https://hermes.pyth.network';\n\t\tconst connection = new SuiPriceServiceConnection(endpoint);\n\n\t\tconst priceUpdateData = await connection.getPriceFeedsUpdateData(staleFeedIds);\n\n\t\tconst wormholeStateId = this.#ctx.config.pyth.wormholeStateId;\n\t\tconst pythStateId = this.#ctx.config.pyth.pythStateId;\n\t\tconst pythClient = new SuiPythClient(this.#ctx.client, pythStateId, wormholeStateId);\n\n\t\tconst updatedObjectIds = await pythClient.updatePriceFeeds(tx, priceUpdateData, staleFeedIds);\n\n\t\tfor (let i = 0; i < staleFeedIds.length; i++) {\n\t\t\tconst coinKey = feedIdToCoinKey[staleFeedIds[i]];\n\t\t\tresult[coinKey] = updatedObjectIds[i];\n\t\t}\n\n\t\treturn result;\n\t}\n\n\tasync getPriceInfoObjectAge(coinKey: string): Promise<number> {\n\t\tconst priceInfoObjectId = this.#ctx.config.getCoin(coinKey).priceInfoObjectId!;\n\t\tconst res = await this.#ctx.client.core.getObject({\n\t\t\tobjectId: priceInfoObjectId,\n\t\t\tinclude: {\n\t\t\t\tcontent: true,\n\t\t\t},\n\t\t});\n\n\t\tif (!res.object?.content) {\n\t\t\tthrow new Error(`Price info object not found for ${coinKey}`);\n\t\t}\n\n\t\tconst priceInfoObject = PriceInfoObject.parse(res.object.content);\n\t\treturn Number(priceInfoObject.price_info.arrival_time);\n\t}\n}\n"],"mappings":";;;;;AAUA,IAAa,mBAAb,MAA8B;CAC7B;CAEA,YAAY,KAAmB;AAC9B,QAAKA,MAAO;;CAGb,MAAM,mBAAmB,IAAiB,SAAkC;AAC3E,QAAKA,IAAK,OAAO,aAAa;EAC9B,MAAM,cAAc,KAAK,KAAK;EAC9B,MAAM,qBAAqB,MAAM,KAAK,sBAAsB,QAAQ;AACpE,MACC,sBACA,cAAc,qBAAqB,MAAO,6BAE1C,QAAO,MAAM,MAAKA,IAAK,OAAO,QAAQ,QAAQ,CAAC;EAOhD,MAAM,aAAa,IAAI,0BAHtB,MAAKA,IAAK,OAAO,YAAY,YAC1B,qCACA,8BACsD;EAE1D,MAAM,WAAW,CAAC,MAAKA,IAAK,OAAO,QAAQ,QAAQ,CAAC,KAAM;EAE1D,MAAM,kBAAkB,MAAM,WAAW,wBAAwB,SAAS;EAE1E,MAAM,kBAAkB,MAAKA,IAAK,OAAO,KAAK;EAC9C,M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kB,MAFL,IAAI,0BAHtB,MAAKA,IAAK,OAAO,YAAY,YAC1B,qCACA,8BACsD,CAEjB,wBAAwB,aAAa;EAE9E,MAAM,kBAAkB,MAAKA,IAAK,OAAO,KAAK;EAC9C,MAAM,cAAc,MAAKA,IAAK,OAAO,KAAK;EAG1C,MAAM,mBAAmB,MAFN,IAAI,cAAc,MAAKA,IAAK,QAAQ,aAAa,gBAAgB,CAE1C,iBAAiB,IAAI,iBAAiB,aAAa;AAE7F,OAAK,IAAI,IAAI,GAAG,IAAI,aAAa,QAAQ,KAAK;GAC7C,MAAM,UAAU,gBAAgB,aAAa;AAC7C,UAAO,WAAW,iBAAiB;;AAGpC,SAAO;;CAGR,MAAM,sBAAsB,SAAkC;EAC7D,MAAM,oBAAoB,MAAKA,IAAK,OAAO,QAAQ,QAAQ,CAAC;EAC5D,MAAM,MAAM,MAAM,MAAKA,IAAK,OAAO,KAAK,UAAU;GACjD,UAAU;GACV,SAAS,EACR,SAAS,MACT;GACD,CAAC;AAEF,MAAI,CAAC,IAAI,QAAQ,QAChB,OAAM,IAAI,MAAM,mCAAmC,UAAU;EAG9D,MAAM,kBAAkB,gBAAgB,MAAM,IAAI,OAAO,QAAQ;AACjE,SAAO,OAAO,gBAAgB,WAAW,aAAa"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { DEEP_SCALAR } from "../utils/config.mjs";
|
|
2
|
+
import { bcs } from "@mysten/sui/bcs";
|
|
3
|
+
import { Transaction } from "@mysten/sui/transactions";
|
|
4
|
+
|
|
5
|
+
//#region src/queries/quantityQueries.ts
|
|
6
|
+
var QuantityQueries = class {
|
|
7
|
+
#ctx;
|
|
8
|
+
constructor(ctx) {
|
|
9
|
+
this.#ctx = ctx;
|
|
10
|
+
}
|
|
11
|
+
async getQuoteQuantityOut(poolKey, baseQuantity) {
|
|
12
|
+
const tx = new Transaction();
|
|
13
|
+
const pool = this.#ctx.config.getPool(poolKey);
|
|
14
|
+
const baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;
|
|
15
|
+
const quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;
|
|
16
|
+
tx.add(this.#ctx.deepBook.getQuoteQuantityOut(poolKey, baseQuantity));
|
|
17
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
18
|
+
transaction: tx,
|
|
19
|
+
include: {
|
|
20
|
+
commandResults: true,
|
|
21
|
+
effects: true
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
const baseOut = Number(bcs.U64.parse(res.commandResults[0].returnValues[0].bcs));
|
|
25
|
+
const quoteOut = Number(bcs.U64.parse(res.commandResults[0].returnValues[1].bcs));
|
|
26
|
+
const deepRequired = Number(bcs.U64.parse(res.commandResults[0].returnValues[2].bcs));
|
|
27
|
+
return {
|
|
28
|
+
baseQuantity: Number(baseQuantity),
|
|
29
|
+
baseOut: Number((baseOut / baseScalar).toFixed(9)),
|
|
30
|
+
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)),
|
|
31
|
+
deepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9))
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
async getBaseQuantityOut(poolKey, quoteQuantity) {
|
|
35
|
+
const tx = new Transaction();
|
|
36
|
+
const pool = this.#ctx.config.getPool(poolKey);
|
|
37
|
+
const baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;
|
|
38
|
+
const quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;
|
|
39
|
+
tx.add(this.#ctx.deepBook.getBaseQuantityOut(poolKey, quoteQuantity));
|
|
40
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
41
|
+
transaction: tx,
|
|
42
|
+
include: {
|
|
43
|
+
commandResults: true,
|
|
44
|
+
effects: true
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
const baseOut = Number(bcs.U64.parse(res.commandResults[0].returnValues[0].bcs));
|
|
48
|
+
const quoteOut = Number(bcs.U64.parse(res.commandResults[0].returnValues[1].bcs));
|
|
49
|
+
const deepRequired = Number(bcs.U64.parse(res.commandResults[0].returnValues[2].bcs));
|
|
50
|
+
return {
|
|
51
|
+
quoteQuantity: Number(quoteQuantity),
|
|
52
|
+
baseOut: Number((baseOut / baseScalar).toFixed(9)),
|
|
53
|
+
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)),
|
|
54
|
+
deepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9))
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async getQuantityOut(poolKey, baseQuantity, quoteQuantity) {
|
|
58
|
+
const tx = new Transaction();
|
|
59
|
+
const pool = this.#ctx.config.getPool(poolKey);
|
|
60
|
+
const baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;
|
|
61
|
+
const quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;
|
|
62
|
+
tx.add(this.#ctx.deepBook.getQuantityOut(poolKey, baseQuantity, quoteQuantity));
|
|
63
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
64
|
+
transaction: tx,
|
|
65
|
+
include: {
|
|
66
|
+
commandResults: true,
|
|
67
|
+
effects: true
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
const baseOut = Number(bcs.U64.parse(res.commandResults[0].returnValues[0].bcs));
|
|
71
|
+
const quoteOut = Number(bcs.U64.parse(res.commandResults[0].returnValues[1].bcs));
|
|
72
|
+
const deepRequired = Number(bcs.U64.parse(res.commandResults[0].returnValues[2].bcs));
|
|
73
|
+
return {
|
|
74
|
+
baseQuantity: Number(baseQuantity),
|
|
75
|
+
quoteQuantity: Number(quoteQuantity),
|
|
76
|
+
baseOut: Number((baseOut / baseScalar).toFixed(9)),
|
|
77
|
+
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)),
|
|
78
|
+
deepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9))
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
async getQuoteQuantityOutInputFee(poolKey, baseQuantity) {
|
|
82
|
+
const tx = new Transaction();
|
|
83
|
+
const pool = this.#ctx.config.getPool(poolKey);
|
|
84
|
+
const baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;
|
|
85
|
+
const quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;
|
|
86
|
+
tx.add(this.#ctx.deepBook.getQuoteQuantityOutInputFee(poolKey, baseQuantity));
|
|
87
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
88
|
+
transaction: tx,
|
|
89
|
+
include: {
|
|
90
|
+
commandResults: true,
|
|
91
|
+
effects: true
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
const baseOut = Number(bcs.U64.parse(res.commandResults[0].returnValues[0].bcs));
|
|
95
|
+
const quoteOut = Number(bcs.U64.parse(res.commandResults[0].returnValues[1].bcs));
|
|
96
|
+
const deepRequired = Number(bcs.U64.parse(res.commandResults[0].returnValues[2].bcs));
|
|
97
|
+
return {
|
|
98
|
+
baseQuantity: Number(baseQuantity),
|
|
99
|
+
baseOut: Number((baseOut / baseScalar).toFixed(9)),
|
|
100
|
+
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)),
|
|
101
|
+
deepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9))
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
async getBaseQuantityOutInputFee(poolKey, quoteQuantity) {
|
|
105
|
+
const tx = new Transaction();
|
|
106
|
+
const pool = this.#ctx.config.getPool(poolKey);
|
|
107
|
+
const baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;
|
|
108
|
+
const quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;
|
|
109
|
+
tx.add(this.#ctx.deepBook.getBaseQuantityOutInputFee(poolKey, quoteQuantity));
|
|
110
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
111
|
+
transaction: tx,
|
|
112
|
+
include: {
|
|
113
|
+
commandResults: true,
|
|
114
|
+
effects: true
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
const baseOut = Number(bcs.U64.parse(res.commandResults[0].returnValues[0].bcs));
|
|
118
|
+
const quoteOut = Number(bcs.U64.parse(res.commandResults[0].returnValues[1].bcs));
|
|
119
|
+
const deepRequired = Number(bcs.U64.parse(res.commandResults[0].returnValues[2].bcs));
|
|
120
|
+
return {
|
|
121
|
+
quoteQuantity: Number(quoteQuantity),
|
|
122
|
+
baseOut: Number((baseOut / baseScalar).toFixed(9)),
|
|
123
|
+
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)),
|
|
124
|
+
deepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9))
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
async getQuantityOutInputFee(poolKey, baseQuantity, quoteQuantity) {
|
|
128
|
+
const tx = new Transaction();
|
|
129
|
+
const pool = this.#ctx.config.getPool(poolKey);
|
|
130
|
+
const baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;
|
|
131
|
+
const quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;
|
|
132
|
+
tx.add(this.#ctx.deepBook.getQuantityOutInputFee(poolKey, baseQuantity, quoteQuantity));
|
|
133
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
134
|
+
transaction: tx,
|
|
135
|
+
include: {
|
|
136
|
+
commandResults: true,
|
|
137
|
+
effects: true
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
const baseOut = Number(bcs.U64.parse(res.commandResults[0].returnValues[0].bcs));
|
|
141
|
+
const quoteOut = Number(bcs.U64.parse(res.commandResults[0].returnValues[1].bcs));
|
|
142
|
+
const deepRequired = Number(bcs.U64.parse(res.commandResults[0].returnValues[2].bcs));
|
|
143
|
+
return {
|
|
144
|
+
baseQuantity: Number(baseQuantity),
|
|
145
|
+
quoteQuantity: Number(quoteQuantity),
|
|
146
|
+
baseOut: Number((baseOut / baseScalar).toFixed(9)),
|
|
147
|
+
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)),
|
|
148
|
+
deepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9))
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
async getBaseQuantityIn(poolKey, targetQuoteQuantity, payWithDeep) {
|
|
152
|
+
const tx = new Transaction();
|
|
153
|
+
const pool = this.#ctx.config.getPool(poolKey);
|
|
154
|
+
const baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;
|
|
155
|
+
const quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;
|
|
156
|
+
tx.add(this.#ctx.deepBook.getBaseQuantityIn(poolKey, targetQuoteQuantity, payWithDeep));
|
|
157
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
158
|
+
transaction: tx,
|
|
159
|
+
include: {
|
|
160
|
+
commandResults: true,
|
|
161
|
+
effects: true
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
const baseIn = Number(bcs.U64.parse(res.commandResults[0].returnValues[0].bcs));
|
|
165
|
+
const quoteOut = Number(bcs.U64.parse(res.commandResults[0].returnValues[1].bcs));
|
|
166
|
+
const deepRequired = Number(bcs.U64.parse(res.commandResults[0].returnValues[2].bcs));
|
|
167
|
+
return {
|
|
168
|
+
baseIn: Number((baseIn / baseScalar).toFixed(9)),
|
|
169
|
+
quoteOut: Number((quoteOut / quoteScalar).toFixed(9)),
|
|
170
|
+
deepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9))
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
async getQuoteQuantityIn(poolKey, targetBaseQuantity, payWithDeep) {
|
|
174
|
+
const tx = new Transaction();
|
|
175
|
+
const pool = this.#ctx.config.getPool(poolKey);
|
|
176
|
+
const baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;
|
|
177
|
+
const quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;
|
|
178
|
+
tx.add(this.#ctx.deepBook.getQuoteQuantityIn(poolKey, targetBaseQuantity, payWithDeep));
|
|
179
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
180
|
+
transaction: tx,
|
|
181
|
+
include: {
|
|
182
|
+
commandResults: true,
|
|
183
|
+
effects: true
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
const baseOut = Number(bcs.U64.parse(res.commandResults[0].returnValues[0].bcs));
|
|
187
|
+
const quoteIn = Number(bcs.U64.parse(res.commandResults[0].returnValues[1].bcs));
|
|
188
|
+
const deepRequired = Number(bcs.U64.parse(res.commandResults[0].returnValues[2].bcs));
|
|
189
|
+
return {
|
|
190
|
+
baseOut: Number((baseOut / baseScalar).toFixed(9)),
|
|
191
|
+
quoteIn: Number((quoteIn / quoteScalar).toFixed(9)),
|
|
192
|
+
deepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9))
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
async getOrderDeepRequired(poolKey, baseQuantity, price) {
|
|
196
|
+
const tx = new Transaction();
|
|
197
|
+
tx.add(this.#ctx.deepBook.getOrderDeepRequired(poolKey, baseQuantity, price));
|
|
198
|
+
const res = await this.#ctx.client.core.simulateTransaction({
|
|
199
|
+
transaction: tx,
|
|
200
|
+
include: {
|
|
201
|
+
commandResults: true,
|
|
202
|
+
effects: true
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
const deepRequiredTaker = Number(bcs.U64.parse(res.commandResults[0].returnValues[0].bcs));
|
|
206
|
+
const deepRequiredMaker = Number(bcs.U64.parse(res.commandResults[0].returnValues[1].bcs));
|
|
207
|
+
return {
|
|
208
|
+
deepRequiredTaker: Number((deepRequiredTaker / DEEP_SCALAR).toFixed(9)),
|
|
209
|
+
deepRequiredMaker: Number((deepRequiredMaker / DEEP_SCALAR).toFixed(9))
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
//#endregion
|
|
215
|
+
export { QuantityQueries };
|
|
216
|
+
//# sourceMappingURL=quantityQueries.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quantityQueries.mjs","names":["#ctx"],"sources":["../../src/queries/quantityQueries.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { bcs } from '@mysten/sui/bcs';\nimport { Transaction } from '@mysten/sui/transactions';\n\nimport type {\n\tBaseQuantityIn,\n\tBaseQuantityOut,\n\tOrderDeepRequiredResult,\n\tQuantityOut,\n\tQuoteQuantityIn,\n\tQuoteQuantityOut,\n} from '../types/index.js';\nimport { DEEP_SCALAR } from '../utils/config.js';\nimport type { QueryContext } from './context.js';\n\nexport class QuantityQueries {\n\t#ctx: QueryContext;\n\n\tconstructor(ctx: QueryContext) {\n\t\tthis.#ctx = ctx;\n\t}\n\n\tasync getQuoteQuantityOut(\n\t\tpoolKey: string,\n\t\tbaseQuantity: number | bigint,\n\t): Promise<QuoteQuantityOut> {\n\t\tconst tx = new Transaction();\n\t\tconst pool = this.#ctx.config.getPool(poolKey);\n\t\tconst baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;\n\t\tconst quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;\n\n\t\ttx.add(this.#ctx.deepBook.getQuoteQuantityOut(poolKey, baseQuantity));\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst baseOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));\n\t\tconst quoteOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));\n\t\tconst deepRequired = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));\n\n\t\treturn {\n\t\t\tbaseQuantity: Number(baseQuantity),\n\t\t\tbaseOut: Number((baseOut / baseScalar).toFixed(9)),\n\t\t\tquoteOut: Number((quoteOut / quoteScalar).toFixed(9)),\n\t\t\tdeepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9)),\n\t\t};\n\t}\n\n\tasync getBaseQuantityOut(\n\t\tpoolKey: string,\n\t\tquoteQuantity: number | bigint,\n\t): Promise<BaseQuantityOut> {\n\t\tconst tx = new Transaction();\n\t\tconst pool = this.#ctx.config.getPool(poolKey);\n\t\tconst baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;\n\t\tconst quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;\n\n\t\ttx.add(this.#ctx.deepBook.getBaseQuantityOut(poolKey, quoteQuantity));\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst baseOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));\n\t\tconst quoteOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));\n\t\tconst deepRequired = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));\n\n\t\treturn {\n\t\t\tquoteQuantity: Number(quoteQuantity),\n\t\t\tbaseOut: Number((baseOut / baseScalar).toFixed(9)),\n\t\t\tquoteOut: Number((quoteOut / quoteScalar).toFixed(9)),\n\t\t\tdeepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9)),\n\t\t};\n\t}\n\n\tasync getQuantityOut(\n\t\tpoolKey: string,\n\t\tbaseQuantity: number | bigint,\n\t\tquoteQuantity: number | bigint,\n\t): Promise<QuantityOut> {\n\t\tconst tx = new Transaction();\n\t\tconst pool = this.#ctx.config.getPool(poolKey);\n\t\tconst baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;\n\t\tconst quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;\n\n\t\ttx.add(this.#ctx.deepBook.getQuantityOut(poolKey, baseQuantity, quoteQuantity));\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst baseOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));\n\t\tconst quoteOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));\n\t\tconst deepRequired = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));\n\n\t\treturn {\n\t\t\tbaseQuantity: Number(baseQuantity),\n\t\t\tquoteQuantity: Number(quoteQuantity),\n\t\t\tbaseOut: Number((baseOut / baseScalar).toFixed(9)),\n\t\t\tquoteOut: Number((quoteOut / quoteScalar).toFixed(9)),\n\t\t\tdeepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9)),\n\t\t};\n\t}\n\n\tasync getQuoteQuantityOutInputFee(\n\t\tpoolKey: string,\n\t\tbaseQuantity: number | bigint,\n\t): Promise<QuoteQuantityOut> {\n\t\tconst tx = new Transaction();\n\t\tconst pool = this.#ctx.config.getPool(poolKey);\n\t\tconst baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;\n\t\tconst quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;\n\n\t\ttx.add(this.#ctx.deepBook.getQuoteQuantityOutInputFee(poolKey, baseQuantity));\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst baseOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));\n\t\tconst quoteOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));\n\t\tconst deepRequired = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));\n\n\t\treturn {\n\t\t\tbaseQuantity: Number(baseQuantity),\n\t\t\tbaseOut: Number((baseOut / baseScalar).toFixed(9)),\n\t\t\tquoteOut: Number((quoteOut / quoteScalar).toFixed(9)),\n\t\t\tdeepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9)),\n\t\t};\n\t}\n\n\tasync getBaseQuantityOutInputFee(\n\t\tpoolKey: string,\n\t\tquoteQuantity: number | bigint,\n\t): Promise<BaseQuantityOut> {\n\t\tconst tx = new Transaction();\n\t\tconst pool = this.#ctx.config.getPool(poolKey);\n\t\tconst baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;\n\t\tconst quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;\n\n\t\ttx.add(this.#ctx.deepBook.getBaseQuantityOutInputFee(poolKey, quoteQuantity));\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst baseOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));\n\t\tconst quoteOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));\n\t\tconst deepRequired = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));\n\n\t\treturn {\n\t\t\tquoteQuantity: Number(quoteQuantity),\n\t\t\tbaseOut: Number((baseOut / baseScalar).toFixed(9)),\n\t\t\tquoteOut: Number((quoteOut / quoteScalar).toFixed(9)),\n\t\t\tdeepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9)),\n\t\t};\n\t}\n\n\tasync getQuantityOutInputFee(\n\t\tpoolKey: string,\n\t\tbaseQuantity: number | bigint,\n\t\tquoteQuantity: number | bigint,\n\t): Promise<QuantityOut> {\n\t\tconst tx = new Transaction();\n\t\tconst pool = this.#ctx.config.getPool(poolKey);\n\t\tconst baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;\n\t\tconst quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;\n\n\t\ttx.add(this.#ctx.deepBook.getQuantityOutInputFee(poolKey, baseQuantity, quoteQuantity));\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst baseOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));\n\t\tconst quoteOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));\n\t\tconst deepRequired = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));\n\n\t\treturn {\n\t\t\tbaseQuantity: Number(baseQuantity),\n\t\t\tquoteQuantity: Number(quoteQuantity),\n\t\t\tbaseOut: Number((baseOut / baseScalar).toFixed(9)),\n\t\t\tquoteOut: Number((quoteOut / quoteScalar).toFixed(9)),\n\t\t\tdeepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9)),\n\t\t};\n\t}\n\n\tasync getBaseQuantityIn(\n\t\tpoolKey: string,\n\t\ttargetQuoteQuantity: number | bigint,\n\t\tpayWithDeep: boolean,\n\t): Promise<BaseQuantityIn> {\n\t\tconst tx = new Transaction();\n\t\tconst pool = this.#ctx.config.getPool(poolKey);\n\t\tconst baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;\n\t\tconst quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;\n\n\t\ttx.add(this.#ctx.deepBook.getBaseQuantityIn(poolKey, targetQuoteQuantity, payWithDeep));\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst baseIn = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));\n\t\tconst quoteOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));\n\t\tconst deepRequired = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));\n\n\t\treturn {\n\t\t\tbaseIn: Number((baseIn / baseScalar).toFixed(9)),\n\t\t\tquoteOut: Number((quoteOut / quoteScalar).toFixed(9)),\n\t\t\tdeepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9)),\n\t\t};\n\t}\n\n\tasync getQuoteQuantityIn(\n\t\tpoolKey: string,\n\t\ttargetBaseQuantity: number | bigint,\n\t\tpayWithDeep: boolean,\n\t): Promise<QuoteQuantityIn> {\n\t\tconst tx = new Transaction();\n\t\tconst pool = this.#ctx.config.getPool(poolKey);\n\t\tconst baseScalar = this.#ctx.config.getCoin(pool.baseCoin).scalar;\n\t\tconst quoteScalar = this.#ctx.config.getCoin(pool.quoteCoin).scalar;\n\n\t\ttx.add(this.#ctx.deepBook.getQuoteQuantityIn(poolKey, targetBaseQuantity, payWithDeep));\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst baseOut = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));\n\t\tconst quoteIn = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));\n\t\tconst deepRequired = Number(bcs.U64.parse(res.commandResults![0].returnValues[2].bcs));\n\n\t\treturn {\n\t\t\tbaseOut: Number((baseOut / baseScalar).toFixed(9)),\n\t\t\tquoteIn: Number((quoteIn / quoteScalar).toFixed(9)),\n\t\t\tdeepRequired: Number((deepRequired / DEEP_SCALAR).toFixed(9)),\n\t\t};\n\t}\n\n\tasync getOrderDeepRequired(\n\t\tpoolKey: string,\n\t\tbaseQuantity: number | bigint,\n\t\tprice: number | bigint,\n\t): Promise<OrderDeepRequiredResult> {\n\t\tconst tx = new Transaction();\n\t\ttx.add(this.#ctx.deepBook.getOrderDeepRequired(poolKey, baseQuantity, price));\n\n\t\tconst res = await this.#ctx.client.core.simulateTransaction({\n\t\t\ttransaction: tx,\n\t\t\tinclude: { commandResults: true, effects: true },\n\t\t});\n\n\t\tconst deepRequiredTaker = Number(bcs.U64.parse(res.commandResults![0].returnValues[0].bcs));\n\t\tconst deepRequiredMaker = Number(bcs.U64.parse(res.commandResults![0].returnValues[1].bcs));\n\n\t\treturn {\n\t\t\tdeepRequiredTaker: Number((deepRequiredTaker / DEEP_SCALAR).toFixed(9)),\n\t\t\tdeepRequiredMaker: Number((deepRequiredMaker / DEEP_SCALAR).toFixed(9)),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;AAiBA,IAAa,kBAAb,MAA6B;CAC5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